1:首先大家有點(diǎn)懵,其實(shí)好好研究下就可以
- 控制橫豎屏Xcode-General-Device Orientation進(jìn)行選擇可以進(jìn)行的旋轉(zhuǎn)方向。
*另一個就是代碼去控制
Appdelegate.m類里面進(jìn)行生命周期添加方法
Appdelegate.h添加屬性isShouAutoRotate-BOOL值
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.isShouAutoRotate == 1) {
return UIInterfaceOrientationMaskLandscape;
}else{
return (UIInterfaceOrientationMaskPortrait);
}
}
//可以添加這個,設(shè)置是否可以進(jìn)行橫豎屏旋轉(zhuǎn)
//一般情況下子類界面進(jìn)行橫豎屏旋轉(zhuǎn)就重寫方法就好了,不需要在這里面添加了
//- (BOOL)shouldAutorotate
//{
// if (self.isShouAutoRotate == 1) {
// return YES;
// }
// return NO;
//}
Appdelegate.m進(jìn)行設(shè)置全局的橫豎屏。
在需要的控制器里面進(jìn)行添加,我們項(xiàng)目是視頻類App,需求就是進(jìn)行橫豎屏界面的旋轉(zhuǎn),進(jìn)入就是橫屏模式。
number=1 可以旋轉(zhuǎn),左右可以進(jìn)行旋轉(zhuǎn)
number=0 禁止旋轉(zhuǎn)
這是ios6之后新增的一組枚舉值,使用組合時更加方便,使用時根據(jù)返回值類型選擇正確的格式。這個屬性最管用,其余的倆個不是很好用。
/*typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) {
UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
} */
(void)appdelegateisShouAutoRotate:(int)number
{
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegate.isShouAutoRotate = number;
}(BOOL)shouldAutorotate
{
return ?;
}
第一個方法不是很建議使用.代碼進(jìn)行控制是最方便的。