- 什么时候使用核心动画
- 只要不需要与用户交互,就可以使用核心动画,
- 核心动画使用最多的场景:一般在转场的时候使用核心动画,核心动画包装的转场动画很强大,其实转场动画真实改变了值.
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));
}];