Animate changes to one or more views using the specified duration and completion handler.
The total duration of the animations, measured in seconds. If you specify a negative value or 0
, the changes are made without animating them.
A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL
.
A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL
.
This method performs the specified animations immediately using the UIViewAnimationOptionCurveEaseInOut
andUIViewAnimationOptionTransitionNone
animation options.
For example, if you want to fade a view until it is totally transparent and then remove it from your view hierarchy, you could use code similar to the following:
[UIView animateWithDuration:0.2 |
animations:^{view.alpha = 0.0;} |
completion:^(BOOL finished){ [view removeFromSuperview]; }]; |
During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.)
UIView.h
eg:
- (void)ShowGameButton {
singleGameBt.alpha = 0;
[UIView animateWithDuration:0.1 animations:^{ singleGameBt.alpha = 1; } completion:^(BOOL finished){ }];
doubleGameBt.alpha = 0;
[UIView animateWithDuration:0.5 animations:^{ doubleGameBt.alpha = 1; } completion:^(BOOL finished){ }];
connectedGameBt.alpha = 0;
[UIView animateWithDuration:0.9 animations:^{ connectedGameBt.alpha = 1; } completion:^(BOOL finished){ }];
gameSettingBt.alpha = 0;
[UIView animateWithDuration:1.3 animations:^{ gameSettingBt.alpha = 1; } completion:^(BOOL finished){ }];
aboutBt.alpha = 0;
[UIView animateWithDuration:1.7 animations:^{ aboutBt.alpha = 1; } completion:^(BOOL finished){ }];
moreGameBt.alpha = 0;
[UIView animateWithDuration:2.1 animations:^{ moreGameBt.alpha = 1; } completion:^(BOOL finished){ }];
}
An array of UIImage
objects to use for an animation.
The array must contain UIImage
objects. You may use the same image object more than once in the array. Setting this property to a value other than nil
hides the image represented by the image
property. The value of this property is nil
by default.
@property image
@property contentMode
(UIView)UIImageView.h
The amount of time it takes to go through one cycle of the images.
The time duration is measured in seconds. The default value of this property is equal to the number of images multiplied by 1/30th of a second. Thus, if you had 30 images, the value would be 1 second.
UIImageView.h
Specifies the number of times to repeat the animation.
The default value is 0, which specifies to repeat the animation indefinitely.
UIImageView.h
eg:
UIImageView* campFireView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
campFireView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"logo1.png"],
[UIImage imageNamed:@"logo2.png"],
[UIImage imageNamed:@"logo3.png"],
[UIImage imageNamed:@"logo4.png"],
[UIImage imageNamed:@"logo5.png"],
[UIImage imageNamed:@"logo5.png"],
[UIImage imageNamed:@"logo5.png"],
[UIImage imageNamed:@"logo5.png"],
[UIImage imageNamed:@"logo4.png"],
[UIImage imageNamed:@"logo3.png"],
[UIImage imageNamed:@"logo2.png"],
[UIImage imageNamed:@"logo1.png"], nil];
campFireView.animationDuration = 2.8;
campFireView.animationRepeatCount = 1;
[campFireView startAnimating];
//[self.view insertSubview:campFireView atIndex:3];
//[self.view bringSubviewToFront:campFireView];
[self.view addSubview:campFireView];
Appends the layer to the receiver’s sublayers
array.
The layer to be added to the receiver’s sublayers
array.
CALayer.h
eg:
// 界面加云层动画
cloudImgview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"clound.png"]];
cloudPoint = CGPointMake(-1.0, -1.0);
cloudImgview.layer.position = CGPointMake(0,108); // start position-->(cloudImgview)
[self.view.layer addSublayer: cloudImgview.layer];
[NSTimer scheduledTimerWithTimeInterval: 0.08
target: self
selector: @selector(handleTimer:)
userInfo: nil
repeats: YES];
//control the clound move 0.08s
- (void) handleTimer:(NSTimer *)timer {
CGSize size;
CGPoint origin;
size = [cloudImgview image].size;
// 设置cloudPoint.x == 1
if( cloudImgview.layer.position.x <= ((size.width / 2) + 1) - self.view.frame.origin.x )
cloudPoint.x = 1.0;
// 设置origin: x递增, y不变(由image1赋值)
if(cloudImgview.layer.position.x + (size.width / 2) + 1 >= 1520)
{
origin.x = 0;
origin.y = cloudImgview.layer.position.y;
}else {
origin = cloudImgview.layer.position;
}
origin.x += cloudPoint.x;
cloudImgview.layer.position = origin; // 动态改变cloudImgview的坐标(x)
/* notify the system that your view’s contents need to be redrawn */
//[ self.view setNeedsDisplayInRect: image1.layer.frame ];
}