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