关于屏幕旋转的问题

当设备方向发生变化时,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 版本的控制啦!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值