码迷,mamicode.com
首页 > 其他好文 > 详细

UIView动画效果

时间:2016-08-08 22:37:29      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

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

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

一: 稳扎稳打:

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

  1.开启一个动画

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

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

  4,提交动画。

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

  //===---开始动画 ---===
    [UIView beginAnimations:nil context:nil];
    //--动画持续时间---
    [UIView setAnimationDuration:2];
    //==--动画延时
    [UIView setAnimationDelay:1];
    //==设置自动返回动画===
    [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(0, 0, 120, 120);

    _view.alpha=0.5;

    //===---提交动画---===
    [UIView commitAnimations];
  */

   2,快捷方式:

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

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

//======------ 块方式,实现UIView动画  ------======
    [UIView animateWithDuration:2 animations:^{//两秒的动画
        _view.center=self.view.center;

    }completion:^(BOOL finished) {//结束时,进行下一个动画

        [UIView animateWithDuration:2 animations:^{
            _view.bounds=CGRectMake(0, 0, 120, 120);

        }completion:^(BOOL finished) {//结束时,进行下个动画,层层嵌套,以此类推。
            [UIView animateWithDuration:2 animations:^{
                 _view.alpha=0.5;
            }completion:^(BOOL finished) {
                [UIView animateWithDuration:1 animations:^{
                    _view.backgroundColor=[UIColor greenColor];
                }];
            }];
        }];
    }];

}

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

UIView动画效果

标签:

原文地址:http://www.cnblogs.com/code-Officer/p/5751161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!