UIViewPropertyAnimator是修改動(dòng)畫屬性的核心類荐吵,它提供了中斷動(dòng)畫姑隅、修改動(dòng)畫中間過(guò)程的功能倘屹;
- (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;
}
/**
開始動(dòng)畫
*/
- (IBAction)startAnim:(UIButton *)sender {
[self.animator startAnimation];
}
/**
暫停動(dòng)畫
*/
- (IBAction)pauseAnim:(UIButton *)sender {
[self.animator pauseAnimation];
}
/**
繼續(xù)動(dòng)畫
*/
- (IBAction)continueAnim:(UIButton *)sender {
UISpringTimingParameters *param = [[UISpringTimingParameters alloc] initWithDampingRatio:0.1];
[self.animator continueAnimationWithTimingParameters:param durationFactor:1];
}
/**
停止動(dòng)畫
*/
- (IBAction)stopAnim:(UIButton *)sender {
[self.animator stopAnimation:true];
}