zoukankan      html  css  js  c++  java
  • 视图自己定义旋转动画 相似百度音乐

    @interface FirstViewController ()

    @property (nonatomic,assign)BOOL isplay;

    @end




    @implementation FirstViewController

    @synthesize isplay;


    - (void)viewDidLoad

    {

        [super viewDidLoad];

        isplay = NO;

        //圆角

        self.imgview.layer.cornerRadius = 150.0 / 2.0;

        self.imgview.layer.masksToBounds = YES;

        

        //加入动画

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

        monkeyAnimation.toValue = [NSNumber numberWithFloat:2.0 *M_PI];

    monkeyAnimation.duration = 1.5f;

    monkeyAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

        monkeyAnimation.cumulative = NO;

        monkeyAnimation.removedOnCompletion = NO; //No Remove

        monkeyAnimation.repeatCount = FLT_MAX;

    [self.imgview.layer addAnimation:monkeyAnimation forKey:@"AnimatedKey"];

        [self.imgview stopAnimating];

        

        // 载入动画 但不播放动画

        self.imgview.layer.speed = 0.2;

        

    }


    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }


    //開始动画

    - (IBAction)startAnimate:(id)sender {

        if (!isplay) {

            isplay = YES;

            self.imgview.layer.speed = 1.0;

            self.imgview.layer.beginTime = 0.0;

            CFTimeInterval pausedTime = [self.imgview.layer timeOffset];

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

            self.imgview.layer.beginTime = timeSincePause;

        }

        

        

    }

    //停止动画并保存当前的角度

    - (IBAction)stioAnimate:(id)sender {

        if (isplay) {

            isplay = NO;

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

            self.imgview.layer.speed = 0.0;

            self.imgview.layer.timeOffset = pausedTime;

        }


    }

    @end

  • 相关阅读:
    小程序开发 access_token 统一管理
    python操作mysql
    Mac版本的idea非正常关闭后,idea打开项目大面积报红
    PySpider爬取去哪儿攻略数据项目
    Python3.9安装PySpider步骤及问题解决
    Selenium 自动化测试工具
    Python 抓取猫眼电影排行
    Python爬虫基本库
    Python 创建一个Django项目
    Python 数据可视化
  • 原文地址:https://www.cnblogs.com/yxwkf/p/5317369.html
Copyright © 2011-2022 走看看