码迷,mamicode.com
首页 > 移动开发 > 详细

ios 如何令一张图片左右晃动

时间:2015-01-09 16:51:48      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

 

   

//开始动画

CABasicAnimation *momAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    momAnimation.fromValue = [NSNumber numberWithFloat:-0.3];

    momAnimation.toValue = [NSNumber numberWithFloat:0.3];

    momAnimation.duration = 0.5;

    momAnimation.repeatCount = CGFLOAT_MAX;

    momAnimation.autoreverses = YES;

    momAnimation.delegate = self;

    [_momImageView.layer addAnimation:momAnimation forKey:@"animateLayer"];

 

//暂停动画,图片未复位

-(void)pauseLayer:(CALayer*)layer

{

    CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];

    layer.speed = 0.0;

    layer.timeOffset = pausedTime;

 

}

 

//重新开始动画

-(void)resumeLayer:(CALayer*)layer{

    CFTimeInterval pausedTime = [layer timeOffset];

    layer.speed = 1.0;

    layer.timeOffset = 0.0;

    layer.beginTime = 0.0;

    CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;

    layer.beginTime = timeSincePause;

 

}

 

//移除动画,图片复位

 

[self.momImageView.layer removeAllAnimations];

ios 如何令一张图片左右晃动

标签:

原文地址:http://www.cnblogs.com/allanliu/p/4213506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!