iOS --用CABasicAnimation实现简单的动画效果

  

直接上代码了,大家可以根据我的代码进行创新,达到自己想要的动画效果!


 UIImage *image=[UIImage imageNamed:@"游戏背景.jpg"];

   UIImageView *backView=[[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 250)];

    self.view=[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

    [self.view addSubview:backView];

    backView.image=image;

       backView.alpha=1.0;

    

     //定义动画

     CABasicAnimation *theAnimation1;

//    //左右摇摆

//    theAnimation1=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];

//    theAnimation1.fromValue=[NSNumber numberWithFloat:0];

//    theAnimation1.toValue=[NSNumber numberWithFloat:-100];

//    

   

    //旋转

//    theAnimation1=[CABasicAnimation animationWithKeyPath:@"transform"];

//    theAnimation1.toValue = [ NSValue valueWithCATransform3D: CATransform3DMakeRotation(3.1415, 0, 0, 1.0) ];

    

    //缩放

    theAnimation1=[CABasicAnimation animationWithKeyPath:@"transform.scale"];

    theAnimation1.toValue = [NSNumber numberWithDouble:1.5];

    

    theAnimation1.duration=1.0;//动画持续时间

    theAnimation1.repeatCount=6;//动画重复次数

    theAnimation1.autoreverses=YES;//是否自动重复


    [backView.layer addAnimation:theAnimation1 forKey:@"animateLayer"];


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值