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


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

查看所有标签

猜你喜欢:

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

构建之法

构建之法

邹欣 / 人民邮电出版社 / 2014-9 / 49.00元

内容简介: 软件工程牵涉的范围很广, 同时也是一般院校的同学反映比较空洞乏味的课程。 但是软件工程的技术对于投身IT 产业的学生来说是非常重要的。作者邹欣有长达20年的一线软件开发经验,他利用业余时间在数所高校进行了长达6年的软件工程教学实践,总结出了在16周的时间内让 同学们通过 “做中学 (Learning By Doing)” 掌握实用的软件工程技术的教学计划,并得到高校师生的积极反馈......一起来看看 《构建之法》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具