UIViewPropertyAnimator是修改动画属性的核心类,它提供了中断动画、修改动画中间过程的功能;
- (void)viewDidLoad {
[super viewDidLoad];
UIView *redView = [[UIView alloc] init];
redView.frame = CGRectMake(100, 100, 100, 100);
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
/*
这是苹果提供的4中曲线
UIViewAnimationCurveEaseInOut, // slow at beginning and end
UIViewAnimationCurveEaseIn, // slow at beginning
UIViewAnimationCurveEaseOut, // slow at end
UIViewAnimationCurveLinear,
*/
UIViewPropertyAnimator *animator = [[UIViewPropertyAnimator alloc] initWithDuration:4 curve:UIViewAnimationCurveEaseIn animations:^{
redView.transform = CGAffineTransformTranslate(redView.transform, 0, 100);
}];
self.animator = animator;
}
/**
开始动画
*/
- (IBAction)startAnim:(UIButton *)sender {
[self.animator startAnimation];
}
/**
暂停动画
*/
- (IBAction)pauseAnim:(UIButton *)sender {
[self.animator pauseAnimation];
}
/**
继续动画
*/
- (IBAction)continueAnim:(UIButton *)sender {
UISpringTimingParameters *param = [[UISpringTimingParameters alloc] initWithDampingRatio:0.1];
[self.animator continueAnimationWithTimingParameters:param durationFactor:1];
}
/**
停止动画
*/
- (IBAction)stopAnim:(UIButton *)sender {
[self.animator stopAnimation:true];
}
网友评论