Andrew
Andrew

Reputation: 16051

How do i make orientation work in my app?

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

Answers (2)

thomas
thomas

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

KevinDTimm
KevinDTimm

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

Related Questions