iphone – 移动CALayers时禁用动画

栏目: IOS · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/2930166/disable-animation-when-moving-calayers
以下代码为动作设置动画,即使我没有使用beginAnimations:context.如何在没有动画的情况下移动它?这是一个新的iphone视图项目,这些是它的唯一更新.
// 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];
}

翻译自:https://stackoverflow.com/questions/2930166/disable-animation-when-moving-calayers


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Ant Colony Optimization

Ant Colony Optimization

Marco Dorigo、Thomas Stützle / A Bradford Book / 2004-6-4 / USD 45.00

The complex social behaviors of ants have been much studied by science, and computer scientists are now finding that these behavior patterns can provide models for solving difficult combinatorial opti......一起来看看 《Ant Colony Optimization》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

MD5 加密
MD5 加密

MD5 加密工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具