码迷,mamicode.com
首页 > 编程语言 > 详细

用POP动画引擎实现弹簧动画(POPSpringAnimation)

时间:2016-01-28 21:00:09      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:

效果图:

技术分享

#import "ViewController.h"
#import <POP.h>

@interface ViewController ()

@property (nonatomic, weak) UIView *testView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor blackColor];
    
    // 初始化测试控件
    UIView *testView         = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    testView.center          = self.view.center;
    testView.backgroundColor = [UIColor redColor];
    self.testView            = testView;
    [self.view addSubview:testView];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    // 初始化弹簧动画
    POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
    springAnimation.springSpeed         = 0;                    // 设置动画速度(常用)
    springAnimation.springBounciness    = 20;                   // 设置弹性大小(常用)
    // springAnimation.dynamicsFriction    = 10;                // 设置阻止弹性的阻力(选用)
    // springAnimation.dynamicsTension     = 100;               // 设置弹性的张力(可以理解为每次变大的程度, 选用)
    if (self.testView.frame.size.width == 100) {
        springAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];
    } else {
        springAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 100, 100)];
    }
    
    // 添加动画
    [self.testView.layer pop_addAnimation:springAnimation forKey:nil];
}

@end

github:https://github.com/RinpeChen/POPSpringAnimationDemo

用POP动画引擎实现弹簧动画(POPSpringAnimation)

标签:

原文地址:http://www.cnblogs.com/Rinpe/p/5167331.html

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