1

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?

3
  • Show us some code. You're probably doing too much on the main thread
    – Stavash
    May 4, 2013 at 15:55
  • @Stavash He probably just has autolayout turned on.
    – Rob
    May 4, 2013 at 16:13
  • Sounds like a very good bet
    – Stavash
    May 4, 2013 at 16:15

1 Answer 1

2

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".

    show 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:

2
  • Rob, thank you for your detailed answer. I will check both solutions and let you know. Thanks again. May 4, 2013 at 19:12
  • Thanks Rob. Both solutions are working, but i want to target iOS 5, so i will use the second one. Thanks again :). May 6, 2013 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.