NSTimer阻止其他动画 [英] NSTimer blocks other animations

查看:59
本文介绍了NSTimer阻止其他动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说明

我有一个NSTimer,它每秒更新一次UILabel.我还有另一个UIImageView,当按下UIButton时,它会在屏幕上滑动.

问题

问题在于,当NSTimer更新UILabel时,UImageView的动画停止完成.

问题

请您告诉我如何在不干扰其他动画的情况下更新计时器?

解决方案

这是

  • 如果要使用自动布局,请通过更改约束而不是更改framecenter来动画化控件的移动.请参见此处,以获取有关如何创建约束的IBOutlet然后在animateWithDuration阻止.

  • 参考文献:

    Description

    I have a NSTimer that updates an UILabel every second. I have another UIImageView that slides in the screen when a UIButton is pressed.

    Issue

    The problem is that when the NSTimer updates the UILabel, the animation of the UImageView stops from completing.

    Question

    Please can you tell me how can i update the timer without messing with the other animations?

    解决方案

    This is a common symptom of having auto layout turned on but are probably trying to slide it across the screen by adjusting the frame or center. Auto layout is a iOS 6+ feature that controls the location and size of various UIView elements. Unfortunately, when you have auto layout on, every time you change a label's value, it will reapply the constraints that dictate where the label should be positioned, defeating your attempts to animate it.

    Two solutions:

    1. Turn off auto layout by opening up your storyboard or NIB, click on the first "document inspector" tab on the rightmost panel, and then uncheck "Use Autolayout".

    2. If you want to use autolayout, animate the moving of the control by changing constraints rather than changing frame or center. See here for an example of how you can create an IBOutlet for a constraint and then change that constraint programmatically in an animateWithDuration block.

    References:

    这篇关于NSTimer阻止其他动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆