- 什么時候使用核心動畫
- 只要不需要與用戶交互,就可以使用核心動畫,
- 核心動畫使用最多的場景:一般在轉場的時候使用核心動畫,核心動畫包裝的轉場動畫很強大,其實轉場動畫真實改變了值.
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"position";
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(250, 500)];
// 必須設置代理
anim.delegate = self;
// 取消反彈
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
[_redView.layer addAnimation:anim forKey:nil];
- 監聽動畫結束:實現代理方法
// 當動畫完成的時候調用
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
// 注意:核心動畫一切都是假象,并不會真實修改layer的屬性
NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position));
}
使用UIView動畫
- 如果需要與用戶交互,使用UIView動畫
- 例子:UIView動畫
[UIView animateWithDuration:0.25 animations:^{
_redView.layer.position = CGPointMake(250, 500);
} completion:^(BOOL finished) {
NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position));
}];