Reputation: 16051
The way my app currently deals with orientation is it repositions all of the items in the view, the layout of which can change as the user interacts with it. I've had numerous problems, such as view's not appearing, views changing before the screen rotates etc. I'm wondering the best way to deal with orientation?
Upvotes: 0
Views: 83
Reputation: 5649
If the landscape-layout is completely different from the portrait-layout I just load all subviews in the init-method of my UIView
-subclass and added them as subviews.
The whole magic is done in the layoutSubviews
-method where I only check in which orientation I am at that moment. Never call alloc
, addSubview
, removeFromSuperview
, ... methods in layoutSubviews
. The layoutSubviews
should only contain code that sets the frame
-properties of subviews.
Referring to your problems:
view not appearing: maybe forgot an addSubview
-call
views changing before the screen rotates: you probably update some frame-properties of subviews outside the layoutSubviews
-method
Upvotes: 1
Reputation: 14376
One possibility - if your app only works with one orientation, disallow orientation changes. This is a reasonable response, some apps are only usable in one view.
Upvotes: 0