开发者

Changing view size when orientation changes

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 do开发者_JS百科ne 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜