需求:項目中某個頁面強制橫屏,其他頁面仍爲豎屏
解決:在viewDidLoad中調用下面的方法
- (void)hengping{
[[BXNavigationItemHelpersetupReturnButtonWithController:self]handleControlEvent:UIControlEventTouchUpInsidewithBlock:^{
if ([[UIDevicecurrentDevice]respondsToSelector:@selector(setOrientation:)])
{
SEL selector =NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocationinvocationWithMethodSignature:[UIDeviceinstanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevicecurrentDevice]];
int val =UIDeviceOrientationPortrait;
[invocation setArgument:&valatIndex:2];
[invocation invoke];
}
[self.navigationControllerpopViewControllerAnimated:YES];
}];
if ([[UIDevicecurrentDevice]respondsToSelector:@selector(setOrientation:)])
{
SEL selector =NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocationinvocationWithMethodSignature:[UIDeviceinstanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevicecurrentDevice]];
int val =UIInterfaceOrientationLandscapeLeft;
[invocation setArgument:&valatIndex:2];
[invocation invoke];
}
}
注意:這個調用的是iOS的私有API,雖然是線程隱式調用,但是審覈的時候還是有風險