How can I prevent the automatic layout from resetting the view pictures?


I have a view with AutoLayout and it works nicely with different screen sizes. There's one element on the screen though that moves around depending on user actions. Whenever I navigate down to a different screen then back to this view, this element gets reset to its original position.

I understand why this happens but how can I prevent it? I do want it to be setup correctly initially but not after the first time.

If you're using Autolayout you should never use setFrame/setBounds because as you've seen Autolayout ignores them and rewrites them when it updates.

The solution is to change the constraints. A constraint has a parameter called constant which is the only thing you can change on a constraint after it has been created. You can also add/remove extra constraints when you need to move NSViews around.

There is a video from WWDC 2012 that had a very good example of how to move views with AutoLayout.