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

来源:互联网 发布:阿里云部署 编辑:程序博客网 时间:2024/06/03 02:54

  

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


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

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

    self.view=[[UIViewalloc] initWithFrame:[[UIScreenmainScreen] applicationFrame]];

    [self.viewaddSubview: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=[CABasicAnimationanimationWithKeyPath:@"transform.scale"];

    theAnimation1.toValue = [NSNumbernumberWithDouble:1.5];

    

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

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

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


    [backView.layeraddAnimation:theAnimation1 forKey:@"animateLayer"];


0 0
原创粉丝点击