1

I'm designing an iOS app in Swift, not using auto-layout. I'm not using auto-layout because if i do, when my labels update, the design resets. For now, I'm designing for an iPhone 4.7 inch, but when i run it on the simulator for any other size device, the design is completely messy.

UPDATE:

I designed my storyboard with the proper constraints. I added my UIImages in the override func viewDidLayoutSubviews and positioned them outside of the screen. When a button is tapped, there should be a sequence of animations which are triggered as well as a UILabel which should have its value updated.

I commented out some code and kept running it to find the problem, and I found that the UIView reset whenever the UILabel updated. The values are being queried from Parse.com.

The design works when the label is NOT being updated. But once the value changes, the view resets...

I tried disabling auto-layout and it works. However, if I have auto-layout turned on it doesn't.

What do I do?

Thanks in advance

Lukesivi
  • 2,206
  • 4
  • 25
  • 43
  • 1
    I'm guessing that you're moving your views by setting frames, which is something you should not do when using auto layout (that is mentioned in the link you provided in your comment). You need to modify the constraints instead. – rdelmar Mar 22 '15 at 19:48
  • Yes, you're right. I'm doing exactly that and now it's working. I commented below for the link I used as a guide. Thanks a lot!! – Lukesivi Mar 22 '15 at 21:39

1 Answers1

1

You should really use Auto Layout. It is the way forward for UI layout. The problem with your labels can surely be fixed with proper constraints.

Make sure you modify constraints instead of frames. The layout engine will calculate the new frames when needed, as helpfully mentioned by @rdelmar.

Rengers
  • 14,911
  • 1
  • 36
  • 54
  • To add on to this, the only time you should consider not using autolayout is [when running into autolayout-related performance issues](http://www.objc.io/issue-22/facebook.html). – Morgan Chen Mar 22 '15 at 19:18
  • Should I code the constraints or use auto layout? http://stackoverflow.com/questions/25773952/animation-blocks-resets-to-original-position-after-updating-text I got the reference here as a quick-fix to just uncheck auto-layout or to code the constraints. Because if not, the UIView disappears whenever the functions in my buttons are tapped... – Lukesivi Mar 22 '15 at 19:32
  • @rinyfo4, don't go with quick fixes. Learn how to use auto layout properly. You should be able to do most, if not all, of it in the storyboard. You should update your question with what specific problems you had when using auto layout. – rdelmar Mar 22 '15 at 19:34
  • This is the way to go about it. Thanks for the insight. For people in the future having trouble i used this link as a guide: http://stackoverflow.com/questions/27371935/how-to-animate-a-uiview-with-constraints-in-swift – Lukesivi Mar 22 '15 at 21:39