Question

I want my UIView subclass to behave so that when it is fitted in portrait orientation is has a certain size and another size when fitted in landscape mode.

Is it possible to have the view indicate to the view controller that's resizing it when the orientation changes that it has this "ideal size"?

To clarify, I'm confident that this is not something that can be done with the autoresizing mask. I also thought that sizeThatFits: would be what I need but I didn't see it get called when the orientation changed.

I'm also aware that I can get this done by overriding layoutSubviews of the superview (or maybe some other method of the view controller but I would like to have this behavior embedded in the view to facilitate reuse.

Was it helpful?

Solution

You get several messages when the device rotates:

- shouldAutorotateToInterfaceOrientation:;
- willRotateToInterfaceOrientation:duration:;
- didRotateFromInterfaceOrientation:

You can use these to re-layout your view when the user rotates.

If you don't want to use a view controller, you can register for the UIDeviceOrientationDidChangeNotification notification.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top