不常用的API类

2016-12-20  本文已影响0人  CoderLHC

CAMediaTimingFunction :https://github.com/YouXianMing/Tween-o-Matic-CN?spm=5176.100239.blogcont29568.8.hA2dRk 设置动画的速度变化

- (void)viewDidLoad {

[super viewDidLoad];

// 初始化layer

CALayer *layer        = [CALayer layer];

layer.frame          = CGRectMake(50, 50, 200, 2);

layer.backgroundColor = [UIColor blackColor].CGColor;

// 终点位置

CGPoint endPosition = CGPointMake(layer.position.x, layer.position.y + 200);

// 动画

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];

animation.fromValue        = [NSValue valueWithCGPoint:layer.position];

animation.toValue          = [NSValue valueWithCGPoint:endPosition];

animation.timingFunction    = [CAMediaTimingFunction functionWithControlPoints:0.20 :0.03 :0.13 :1.00];

layer.position              = endPosition;

animation.duration          = 1.f;

// 添加动画

[layer addAnimation:animation forKey:nil];

// 添加layer

[self.view.layer addSublayer:layer];

}

上一篇下一篇

猜你喜欢

热点阅读