移动CALayers时禁用动画 [英] Disable animation when moving CALayers
本文介绍了移动CALayers时禁用动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码为动作设置动画,即使我没有使用 beginAnimations:context
。如何在没有动画的情况下移动它?这是一个新的iphone视图项目,这些是它的唯一更新。
The following code animates the movement, even though I didn't use beginAnimations:context
. How do I get it to move without animating? This is a new iphone view project, and these are the only updates to it.
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
sublayer = [CALayer new];
sublayer.backgroundColor = [[UIColor redColor] CGColor];
sublayer.frame = CGRectMake(0, 0, 100, 100);
[self.view.layer addSublayer:sublayer];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
sublayer.position = [[touches anyObject] locationInView:self.view];
}
推荐答案
最简单的方法是通过将位置代码放入事务来覆盖动画持续时间:
The simplest way to do it is to override the animation duration by putting the position code into a transaction:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[CATransaction begin];
[CATransaction setAnimationDuration:0];
sublayer.position = [[touches anyObject] locationInView:self.view];
[CATransaction commit];
}
这篇关于移动CALayers时禁用动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文