1.其他界面是豎屏,有個界面只支持橫屏
#pragma mark 強制橫屏的方法
- (BOOL)shouldAutorotate {
returnNO;
}
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
returnUIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
returnUIInterfaceOrientationLandscapeRight;
}
2.其他界面是豎屏,有個界面又要支持橫屏又要支持豎屏
AppDelegate.h 增加 @property(nonatomic,assign)NSInteger?allowRotation;//全局參數(shù)是否允許橫豎屏切換
初始_allowRotaion = 0
#pragma mark 設(shè)置是否可以橫豎屏切換
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
if(_allowRotation==1) {
returnUIInterfaceOrientationMaskAllButUpsideDown;//這個可以根據(jù)自己的需求設(shè)置旋轉(zhuǎn)方向
}
else
{
return(UIInterfaceOrientationMaskPortrait);
}
}
在你需要的界面viewwillAppaear設(shè)置_allowRotaion ?= 1
點擊觸發(fā)橫屏代碼
if([[UIDevicecurrentDevice]respondsToSelector:@selector(setOrientation:)]) {
SELselector =NSSelectorFromString(@"setOrientation:");
NSInvocation*invocation = [NSInvocationinvocationWithMethodSignature:[UIDeviceinstanceMethodSignatureForSelector:selector]];
[invocationsetSelector:selector];
[invocationsetTarget:[UIDevicecurrentDevice]];
intval =UIInterfaceOrientationLandscapeRight;
[invocationsetArgument:&valatIndex:2];
[invocationinvoke];
}