WEB开发网
开发学院手机开发iPhone 开发 iOS如何处理设备方向变化 阅读

iOS如何处理设备方向变化

 2010-12-19 07:19:19 来源:WEB开发网   
核心提示:also eliminates the need to litter your view controller code with conditional checks for the current orientation.In order to support an alternate landscape inte
also eliminates the need to litter your view controller code with conditional checks for the current orientation.

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

上一页  4 5 6 7 8 9 10 11  下一页

Tags:iOS 如何 处理

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接