简易动画的实现

•在iOS开发中,想实现一些小动画是非常容易的

  • 系统会根据某个属性值的改变自动形成动画
  • 比如x值本来是10,然后x值突然改为了100,系统会通过平移动画的方式让x值慢慢从10变到100
•简易动画大致有2种方式:

1. 头尾式

[UIView beginAnimations:nilcontext:nil];

/** 需要执行动画的代码 **/

[UIView commitAnimations];


示例程序如下:
<span style="color:#3333ff;">   </span> //开始动画
    [UIView beginAnimations:nil context:nil];
    
    //设置动画时长
    [UIView setAnimationDuration:1.0f];
    
    /*
     UIViewAnimationCurveEaseInOut,          开始和结束慢速slow at beginning and end
     UIViewAnimationCurveEaseIn,             开始慢速slow at beginning
     UIViewAnimationCurveEaseOut,            结束时慢速slow at end
     UIViewAnimationCurveLinear              匀速
     */
    //设置动画模式
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    
    //设置重复次数default = 0.0  最大值:MAXFLOAT  HUGE_VAL
    [UIView setAnimationRepeatCount:1];
    
    //设置动画的代理
    [UIView setAnimationDelegate:self];
    设置动画将要开始时的代理方法
    [UIView setAnimationWillStartSelector:@selector(animationWillStart)];
    
    //设置动画结束时的代理方法
    [UIView setAnimationDidStopSelector:@selector(moveToButtom)];
    
    //执行动画的代码
    CGRect frame = self.view.frame;
    frame.origin.x = self.window.bounds.size.width - 100;
    
    [self beginAnimationWithStopSelector:@selector(moveToButtom) frame:frame];

    //提交动画
    //[UIView commitAnimations];


2. Block式

[UIView animateWithDuration:0.5animations:^{

   /**需要执行动画的代码 **/

}];


/**参数:

       Duration:动画持续时长

     */

[UIView animateWithDuration:2.0f animations:^{

        

        /**需要执行动画的代码 **/

        

}completion:^(BOOL finished) {

       

 /**动画结束执行的代码 **/

}];







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值