直接上代码了,大家可以根据我的代码进行创新,达到自己想要的动画效果!
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"];