动画Animation两种实现方式的不同效果

来源:互联网 发布:淘宝买家秀点赞没了 编辑:程序博客网 时间:2024/04/28 11:03

iOS的常用的动画Animation有两种不同方式。

一种是commit方式,一种是block方式。


最简单的实现:

1.commit方式

[UIView beginAnimations:nil context:nil];  //设定动画持续时间 [UIView setAnimationDuration:2]; //动画的内容 [self.view setBackgroundColor:[UIColor lightGrayColor]];[UIView commitAnimations];

2.block方式

    [UIView animateWithDuration:2 animations:^{        [self.view setBackgroundColor:[UIColor lightGrayColor]];    }];


但是这两种方式,在显示效果上是有差异的。

以点击button变色为例,

commit方式会根据你点击,重置效果从新开始动画,

block方式则在动画显示期间不会在接收新的动画,等动画完了之后再接受。


上例中,若两秒内点击button多次,commit会不等效果结束,每次点击就会从新开始动画;block则只会完成一次动画效果,不管2秒内点击了多少次。



0 0
原创粉丝点击