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

iOS如何处理设备方向变化

 2010-12-19 07:19:19 来源:WEB开发网   
核心提示:Managing a View Controller’s Interface OrientationThe accelerometers in iOS?based devices make it possible to determine the current orientation of the device. T

Managing a View Controller’s Interface Orientation

The accelerometers in iOS?based devices make it possible to determine the current orientation of the device. The UIKit framework takes advantage of this information and uses it to orient your application’s user interface to match the device orientation when appropriate. Although applications support only a portrait orientation by default, you can configure your view controllers to support other orientations as needed.

Supporting alternate orientations requires additional configuration for both your views and the view controllers that manage them. The simplest way to support multiple interface orientations is to do the following:

Override your view controller’s shouldAutorotateToInterfaceOrientation: method and declare the orientations it supports; see “Declaring the Supported Interface Orientations.”

Configure the autoresizing mask for each view in your view controller’s view hierarchy; see “Configuring Your Views to Support Multiple Orientations.”

These two steps should be sufficient for many applications. However, if the autoresizing behavior of views does not yield the layout you need for each orientation, you can override additional view controller methods and use them to tweak your layout when orientation changes occur. The UIViewController class provides a series of notifications that let you respond to different phases of the orientation change and make adjustments to your views (or other parts of your application) as needed. These notifications are described in more detail in“Responding to Orientation Changes”

Understanding the Rotation Process

When the orientation of an iOS?based device changes, the system sends out aUIDeviceOrientationDidChangeNotification notification to let any interested parties know that the change occurred. By default, the UIKit framework intercepts this notification and uses it to update your interface orientation

1 2 3 4 5 6  下一页

Tags:iOS 如何 处理

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读