您的位置:首页 > 移动开发 > IOS开发

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

2014-06-26 14:59 501 查看
  
直接上代码了,大家可以根据我的代码进行创新,达到自己想要的动画效果!

 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"];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息