1.其他界面是竖屏,有个界面只支持横屏
#pragma mark 强制横屏的方法
- (BOOL)shouldAutorotate {
returnNO;
}
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
returnUIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
returnUIInterfaceOrientationLandscapeRight;
}
2.其他界面是竖屏,有个界面又要支持横屏又要支持竖屏
AppDelegate.h 增加 @property(nonatomic,assign)NSInteger allowRotation;//全局参数是否允许横竖屏切换
初始_allowRotaion = 0
#pragma mark 设置是否可以横竖屏切换
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
if(_allowRotation==1) {
returnUIInterfaceOrientationMaskAllButUpsideDown;//这个可以根据自己的需求设置旋转方向
}
else
{
return(UIInterfaceOrientationMaskPortrait);
}
}
在你需要的界面viewwillAppaear设置_allowRotaion = 1
点击触发横屏代码
if([[UIDevicecurrentDevice]respondsToSelector:@selector(setOrientation:)]) {
SELselector =NSSelectorFromString(@"setOrientation:");
NSInvocation*invocation = [NSInvocationinvocationWithMethodSignature:[UIDeviceinstanceMethodSignatureForSelector:selector]];
[invocationsetSelector:selector];
[invocationsetTarget:[UIDevicecurrentDevice]];
intval =UIInterfaceOrientationLandscapeRight;
[invocationsetArgument:&valatIndex:2];
[invocationinvoke];
}