項目中某個頁面強制橫屏

需求:項目中某個頁面強制橫屏,其他頁面仍爲豎屏

解決:在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,雖然是線程隱式調用,但是審覈的時候還是有風險


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章