Alfonso
Alfonso

Reputation: 8482

Custom UIView rotation with a view controller

I have an interface which consists of two views, which in landscape mode are to the left and to the right of the screen. Now when rotating to portrait, the views should be on top of each other and rotate themselves according to the device orientation (I hope the ASCII art helps to show what I mean, this should happen when the user rotates the device clockwise).

           -----
-------    | A |
| A B | => | B |
-------    -----

The screen itself should not rotate, only the views. I could probably solve this by swapping the views when auto rotating, but then there would be a visible break when I switch the views.

How would I go about it when I want the two views to rotate separately?

Upvotes: 2

Views: 1517

Answers (1)

PengOne
PengOne

Reputation: 48398

I achieved something like this using animations in viewWillRotateToOrientation:. Essentially, the idea I had was to move the center of each view (or, in same cases, the frame) inside an animation that began when a rotation even was detected.

The difficulty with my approach is that I also needed to move the subviews around in viewWillAppear since the subviews didn't always get the message through viewWillRotateToOrientation: when they were moved off-screen or unloaded.

For the depiction you have above, you could just anchor the top left corner or A and the bottom right corner of B using the autoresizing masks (in IB or programmatically). However, if you want something more exotic, as I did, then try using animations.

Upvotes: 2

Related Questions