animateWithDuration

一般写在viewDidAppear


+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

其中,

duration为动画持续的时间。

animations为动画效果的代码块。

下面是可以设置动画效果的属性:

frame

bounds

center

transform

alpha

backgroundColor

contentStretch

例如一个视图淡出屏幕,另外一个视图出现的代码:

[UIView animateWithDuration:1.0 animations:^{

firstView.alpha = 0.0;

secondView.alpha = 1.0;

}];

completion为动画执行完毕以后执行的代码块

options为动画执行的选项。可以参考这里

delay为动画开始执行前等待的时间

如何实现连续的动画?

可以在completion代码块中添加动画。

下面是实例代码:

[UIView animateWithDuration:2.0

animations:^{

oldImageView.alpha = 0.0;

newImageView.alpha = 1.0;

//imageView.center = CGPointMake(500.0, 512.0);

}

completion:^(BOOL finished){

[UIView animateWithDuration:4.0

animations:^{

newImageView.center = CGPointMake(500.0, 512.0);

}];

}];

具体效果就是一幅图片渐渐消失,另一幅图片出现,然后图片的位置移动。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 3,206评论 1 23
  • 先看看CAAnimation动画的继承结构 CAAnimation{ CAPropertyAnimation { ...
    时间不会倒着走阅读 1,712评论 0 1
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,158评论 5 13
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,599评论 6 30
  • // //UIView.h //UIKit // //Copyright (c) 2005-2015 Apple ...
    李某lkb阅读 1,761评论 0 0