zoukankan      html  css  js  c++  java
  • 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];

  • 相关阅读:
    codevs1127
    codevs1041
    C#预处理指令
    C#基本语句与C++区别
    iOS.TextKit.01.凸版印刷效果
    iOS.常用设计模式.02.委托模式
    iOS.常用设计模式.01.单例模式
    iOS.iPad.03.UIModal
    iOS.iPad.02.UIPopoverViewController
    iOS.iPad.01.UISplitViewController
  • 原文地址:https://www.cnblogs.com/allanliu/p/4213506.html
Copyright © 2011-2022 走看看