iphone – 移动CALayers时禁用动画

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

内容简介:翻译自: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


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

查看所有标签

猜你喜欢:

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

马云如是说

马云如是说

朱甫 / 中国经济出版社 / 2008-1-1 / 39.80元

任何一个企业家的成功,都需要一种特立独行的精神。换尔言之,他一定是不断地否定别人的反对意见,坚持自己独特的观点,才能够真正走向大成功。在中国企业家群像里,马云就是这样一个特立独行的人。 目录 *永不放弃——马云论创业精神 *天下没有难做的生意——马云论经营理念 *B2B时代——马云论电子商务 *网络只是一个工具——马云论互联网与网络公司 *太多钱会坏事——马云论......一起来看看 《马云如是说》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试