gpt4 book ai didi

iphone - 移动 CALayer 时禁用动画

转载 作者:太空狗 更新时间:2023-10-30 03:35:16 24 4
gpt4 key购买 nike

尽管我没有使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com