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

 

   

//开始动画

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];

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。