尽管我没有使用 beginAnimations:context
,但以下代码为移动设置了动画。我如何让它在没有动画的情况下移动?这是一个新的 iphone View 项目,这些是对其的唯一更新。
// 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];
}
最佳答案
最简单的方法是通过将位置代码放入交易来覆盖动画持续时间:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[CATransaction begin];
[CATransaction setAnimationDuration:0];
sublayer.position = [[touches anyObject] locationInView:self.view];
[CATransaction commit];
}
关于iphone - 移动 CALayer 时禁用动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2930166/