iOS如何处理设备方向变化
2010-12-19 07:19:19 来源:WEB开发网In order to support an alternate landscape interface, you have to do the following:
Implement two view controller objects:
One should present a portrait-only interface.
One should present a landscape-only interface.
Register for the UIDeviceOrientationDidChangeNotification notification. In your handler method, present or dismiss the alternate view controller based on the current device orientation.
Because view controllers normally manage orientation changes internally, you have to tell each view controller to display itself in one orientation only. The implementation of the primary view controller then needs to detect device orientation changes and present the alternate view controller when the appropriate orientation change occurs. When the orientation returns to the primary orientation, the primary view controller would then dismiss the alternate view controller.
Listing 2-5 shows the key methods you would need to implement in a primary view controller that supports a portrait orientation. As part of its initialization, this view controller registers to receive orientation changed notifications from the shared UIDevice object. When such a notification arrives, the orientationChanged:method then presents or dismisses the landscape view controller depending on the current orientation.
Listing 2-5 Presenting the landscape view controller
@implementation PortraitViewController 更多精彩赞助商链接
热点阅读最新推荐
飞鹰联盟成员网站 Copyright © 2003-2013 CnCms.Com. All Rights Reserved 京ICP备10000768号
|