需求:项目中某个页面强制横屏,其他页面仍为竖屏
解决:在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,虽然是线程隐式调用,但是审核的时候还是有风险