zoukankan      html  css  js  c++  java
  • 用POP动画模拟真实秒钟摆动效果

    用POP动画模拟真实秒钟摆动效果

    静态图:

    动画图:

    此处用到了POP中的Spring系列动画,现提供源码如下:

    SecondClockView.h 与 SecondClockView.m

    //
    //  SecondClockView.h
    //  YouXianMingClock
    //
    //  Created by YouXianMing on 14-10-12.
    //  Copyright (c) 2014年 YouXianMing. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface SecondClockView : UIView
    
    /**
     *  Use in conjunction with 'springSpeed' to change animation effect. Values are converted into corresponding dynamics constants. Defined as a value in the range [0, 20]. Defaults to 18.
     */
    @property (nonatomic, assign) CGFloat springBounciness;
    
    /**
     *  The mass used in the dynamics simulation.
     */
    @property (nonatomic, assign) CGFloat dynamicsMass;
    
    /**
     *  Use in conjunction with 'springBounciness' to change animation effect. Values are converted into corresponding dynamics constants. Defined as a value in the range [0, 20]. Defaults to 18.
     */
    @property (nonatomic, assign) CGFloat springSpeed;
    
    /**
     *  给与时间进行的动画
     *
     *  @param second 当前秒
     */
    - (void)startAnimationWithSecond:(float)second;
    
    @end
    //
    //  SecondClockView.m
    //  YouXianMingClock
    //
    //  Created by YouXianMing on 14-10-12.
    //  Copyright (c) 2014年 YouXianMing. All rights reserved.
    //
    
    #import "SecondClockView.h"
    #import "POP.h"
    
    /**
     *  将角度转换为弧度
     *
     *  @param d 角度
     *
     *  @return 弧度
     */
    #define DEGREES__TO__RADIANS(d)  ((d) * M_PI / 180.f)
    
    @interface SecondClockView ()
    
    {
        
        BOOL firstTime;
        
    }
    
    @end
    
    @implementation SecondClockView
    
    - (void)startAnimationWithSecond:(float)second
    {
        // 秒钟
        POPSpringAnimation *springAnimation = 
            [POPSpringAnimation animationWithPropertyNamed:kPOPLayerRotation];
        
        springAnimation.fromValue        = @(DEGREES__TO__RADIANS((360)/60.f)*(second - 1) + DEGREES__TO__RADIANS(-90));
        if (firstTime == NO) {
            firstTime = YES;
            springAnimation.fromValue    = @(0);
        }
        springAnimation.toValue          = @(DEGREES__TO__RADIANS((360)/60.f)*second + DEGREES__TO__RADIANS(-90));
        springAnimation.springBounciness = (_springBounciness > 0 && _springBounciness <= 20)?_springBounciness:18.f;
        springAnimation.dynamicsMass     = (_dynamicsMass > 0)?_dynamicsMass:1.5f;
        springAnimation.springSpeed      = (_springSpeed > 0 && _springSpeed <= 20)?_springSpeed:18.f;
        [self.layer pop_addAnimation:springAnimation forKey:nil];
    }
    
    @end

    使用时候的情形

    使用的时候请引入POP库

  • 相关阅读:
    maven基础依赖外部lib包(依赖钉钉sdk为例)
    JVM的内存区域划分
    EF6 根据数据库字段说明,生成字段注释
    js上传图片,js图片转换为Base64
    Jquery用append()方法新增加的元素事件失效
    MVC添加区域路由问题
    JObject获取JSON格式字符串数据
    百度地图WebApi根据地址解析经纬度和根据经纬度解析地址
    sqlserver函数根据经纬度计算两点之间的距离
    AdminLTE-2.4.0-rc文件添加到项目中报错 错误 1 “tsc.exe”已退出,代码为 1。 M.Website
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4020939.html
Copyright © 2011-2022 走看看