IOS常用的简单动画

第一种 隐式动画

这是一种最简单的动画,不用设置定时器,不用考虑线程或者重画

实现代码:

#import <QuartzCore/QuartzCore.h>

-(void)clickButton:(UIButton*)button
{
    [UIView beginAnimations:nil
                    context:nil];
    CGAffineTransform transform=CGAffineTransformMakeTranslation(180, 200);
    [self.imageView.layer setAffineTransform:transform];
    self.imageView.layer.opacity=1;
    [UIView commitAnimations];
}

操作layer,IOS的动画都是操作layer

 第二种、显示动画

 
    CABasicAnimation *opAnim=[CABasicAnimation animationWithKeyPath:@"opacity"];
    opAnim.duration=6.0;
    opAnim.fromValue=[NSNumber numberWithFloat:25];
    opAnim.toValue=[NSNumber numberWithFloat:1.0];
    opAnim.cumulative=YES;
    opAnim.repeatCount=1;
    [self.imageView.layer addAnimation:opAnim forKey:@"animateOpacity"];
    
    CGAffineTransform moveTransform=CGAffineTransformMakeTranslation(200, 200);
    CABasicAnimation *moveAnim=[CABasicAnimation animationWithKeyPath:@"transform"];
    moveAnim.duration=6.0;
    moveAnim.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(moveTransform)];
    [self.imageView.layer addAnimation:moveAnim forKey:@"animateTransform"];

第三种、关键帧显示动画

CAKeyframeAnimation *opAnim=[CAKeyframeAnimation animationWithKeyPath:@"opacity"];
    opAnim.duration=6.0;
    opAnim.values=@[@0.25,@0.75,@1.0];
    opAnim.keyTimes=@[@0.0,@0.5,@1.0];
    [self.imageView.layer addAnimation:opAnim forKey:@"animateOpacity"];
    
    CGAffineTransform moveTransform=CGAffineTransformMakeTranslation(180, 200);
    CABasicAnimation *moveAnim=[CABasicAnimation animationWithKeyPath:@"transform"];
    moveAnim.duration=6.0;
    moveAnim.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(moveTransform)];
    moveAnim.delegate=self;
    [self.imageView.layer addAnimation:moveAnim forKey:@"animateTransform"];


values是一个值的数组

keyTimes是一个每个帧片段持续的时间比例,取值范围是0.0-1.0之前


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值