iphone - 移动 CALayer 时禁用动画

标签 iphone objective-c core-animation

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

相关文章:

objective-c - 翻转、增长和翻译动画

ios - 如何自定义模态视图 Controller 呈现动画?

ios - 同时分别为图层变换的旋转和缩放比例设置不同的持续时间

iphone - 将更新的数据库复制到 ios sdk 中的设备中

ios - 相对于屏幕尺寸缩放 UIFont 尺寸

ios - 如何将 UIImage 传递给 phonegap 以在图像控件中查看?

Iphone 在滚动中定义多个 ui 组件的最佳方式

iphone - UITableViewCell 自定义图片大小、阴影和边框

ios - iOS 中的受监管设备和应用程序限制

ios - 自定义表格 View 单元格