当设备方向发生变化时,UIKit 会收到相应通知,这个时候; UIApplication object 和 the root view controller 来决定, 这个旋转是否可以。如果两者都说可以,那么就行;否则的话,就转不了。
Returns whether the view controller’s contents should auto rotate.
- (BOOL)shouldAutorotate
Return Value
YES if the content should rotate, otherwise NO. Available in iOS 6.0 and later.
Declared in
UIViewController.h
-(BOOL) shouldAutorotate{
return YES;
}
supportedInterfaceOrientations
Returns all of the interface orientations that the view controller supports.
- (NSUInteger)supportedInterfaceOrientations
Return Value
A bit mask specifying which orientations are supported. See UIInterfaceOrientationMask for valid bit-maskvalues. The value returned by this method must not be 0.
Discussion
When the user changes the device orientation, the system calls this method on the root view controller or thetopmost presented view controller that fills the window. If the view controller supports the new orientation,the window and view controller are rotated to the new orientation. This method is only called if the viewcontroller’s shouldAutorotate (page 57) method returns YES.
Override this method to report all of the orientations that the view controller supports. The default values fora view controller’s supported interface orientations is set to UIInterfaceOrientationMaskAll for the iPadidiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.
The system intersects the view controller’s supported orientations with the app's supported orientations (asdetermined by the Info.plist file or the app delegate'sapplication:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate.
2012-09-19 | © 2012 Apple Inc. All Rights Reserved.58
UIViewController Class Reference
Instance Methods
Availability
Available in iOS 6.0 and later.
Declared in
UIViewController.h
注意其中的对应关系:
iOS 6中, info.plist 中 supportedInterfaceOrientations 这一项的填写
代码中对应:
application:supportedInterfaceOrientationsForWindow:
这个是一统江湖。
然后就是每一个具体controller 里面:
shouldAutoRotate
supportedInterfaceOrientations
要支持iOS 5及以前的呢?
shouldAutoRotateToInterfaceOrientation:
在这里就会涉及到代码对于iOS 版本的控制啦!