WEB开发网
开发学院手机开发iPhone 开发 常用 IPHONE 编程 基础代码 阅读

常用 IPHONE 编程 基础代码

 2010-03-10 16:08:00 来源:WEB开发网   
核心提示:UIImageView *myAnimatedView = [UIImageView alloc];[myAnimatedView initWithFrame:[self bounds]];myAnimatedView.animationImages = myImages;myAnimatedView.animatio

UIImageView *myAnimatedView = [UIImageView alloc];

[myAnimatedView initWithFrame:[self bounds]];

myAnimatedView.animationImages = myImages;

myAnimatedView.animationDuration = 0.25; // seconds

myAnimatedView.animationRepeatCount = 0; // 0 = loops forever

[myAnimatedView startAnimating];

[self addSubview:myAnimatedView];

[myAnimatedView release];

Animation: Move an object

Show something moving across the screen. Note: this type of animation is "fire and forget" -- you cannot obtain any information about the objects during animation (such as current position). If you need this information, you will want to animate manually using a Timer and adjusting the x&y coordinates as necessary.

这个需要导入QuartzCore.framework

CABasicAnimation *theAnimation;

theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];

theAnimation.duration=1;

theAnimation.repeatCount=2;

theAnimation.autoreverses=YES;

theAnimation.fromValue=[NSNumber numberWithFloat:0];

theAnimation.toValue=[NSNumber numberWithFloat:-60];

[view.layer addAnimation:theAnimation forKey:@"animateLayer"];

Draggable items

Here's how to create a simple draggable image.

1. Create a new class that inherits from UIImageView

@interface myDraggableImage : UIImageView { }

2. In the implementation for this new class, add the 2 methods:

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event

{ // Retrieve the touch point

CGPoint pt = [[touches anyObject] locationInView:self];

startLocation = pt;

[[self superview] bringSubviewToFront:self];

}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event

{ // Move relative to the original touch point

上一页  1 2 3 4 5  下一页

Tags:常用 IPHONE 编程

编辑录入:coldstar [复制链接] [打 印]
赞助商链接