UIView动画效果

时间:2023-03-09 09:43:23
UIView动画效果

做出UI界面,实现程序功能,是重中之重,但是通过动画提升使用体验,一般人应该不会拒绝吧。

那么问题又来了,怎么做?

一: 稳扎稳打:

一步一步来吧,毕竟,心急吃不了热豆腐。

1.开启一个动画

2,设置该动画的各种属性:动画时长、延时执行、自动返回、动画重复次数、转场动画。。。

3,设置动画的UI的结束时的状态是什么,UI的最终位置等。

4,提交动画。

大功告成。具体细节如下:

  //===---开始动画 ---===
[UIView beginAnimations:nil context:nil];
//--动画持续时间---
[UIView setAnimationDuration:];
//==--动画延时
[UIView setAnimationDelay:];
//==设置自动返回动画===
[UIView setAnimationRepeatAutoreverses:YES];
//==---设置动画重复次数---==
[UIView setAnimationRepeatCount:2.5]; //==--为动画设置代理 1 --==
[UIView setAnimationDelegate:self];
//===---设置动画完成时的动作 2 ---===
[UIView setAnimationDidStopSelector:@selector(changeColor)]; //设置转场动画
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_view cache:YES]; //===---动画要完成的效果---===
_view.center=self.view.center; _view.bounds=CGRectMake(, , , ); _view.alpha=0.5; //===---提交动画---===
[UIView commitAnimations];
*/

2,快捷方式:

如果感觉上面的步骤太繁琐,那就只能用那一招了。

动画的“块”捷方式,使用UIView调用类方法,根据实际所需,选择不同的方法。尤其是可以将多个动画过程连续起来执行(在一个动画结束时,进行下一个动画)。

//======------ 块方式,实现UIView动画  ------======
[UIView animateWithDuration: animations:^{//两秒的动画
_view.center=self.view.center; }completion:^(BOOL finished) {//结束时,进行下一个动画 [UIView animateWithDuration: animations:^{
_view.bounds=CGRectMake(, , , ); }completion:^(BOOL finished) {//结束时,进行下个动画,层层嵌套,以此类推。
[UIView animateWithDuration: animations:^{
_view.alpha=0.5;
}completion:^(BOOL finished) {
[UIView animateWithDuration: animations:^{
_view.backgroundColor=[UIColor greenColor];
}];
}];
}];
}]; }

欲穷千里目,更上一层楼!