学习笔记 8月上
1、核心动画保留执行动画之后的效果
// 让图层保持动画执行完毕之后的状态
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
2、核心动画的缺点:所看到的都是假象,实际的本质是没变的
在动画执行的过程中,图层的position等任何属性一直都是没变的。
所以开发中,图层用的比较多的动画是转场动画
3、UI动画的实现和监听
[UIView beginAnimations:nil context:nil];
self.iconView.center = CGPointMake(200, 300);
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationStop)];// 动画执行完会调用 animationStop
[UIView commitAnimations];
使用block实现:
[UIView animateWithDuration:1.0 animations:^{
self.iconView.center = CGPointMake(200, 300);
} completion:^(BOOL finished) {
NSLog(@"动画执行完毕");
}];
4、添加一个定时器
// 1秒内刷新60次 创建一个定时器
if (self.link) return; // 如果此时已经有定时器了,则不再创建
CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
self.link = link;
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
删除定时器:
// 方法一
// [self.link removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
// self.link = nil;
// 或者也可以这样写 invalidate: 使无效 ; 使无价值 ;
[self.link invalidate];
self.link = nil;