ios开发 present 出来的viewcontroller 强制横竖屏切换代码分享 (代码不解释)

来源:互联网 发布:360浏览器 网络收藏夹 编辑:程序博客网 时间:2024/05/21 07:10


添加下面代码到 控制器中



@property(nonatomic,assign)BOOL isPortraitMode;@synthesize isPortraitMode=_isPortraitMode;- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{         if (_isPortraitMode) {            return UIInterfaceOrientationPortrait;        }else{            return UIInterfaceOrientationLandscapeRight;        } }-(NSUInteger)supportedInterfaceOrientations{         if (_isPortraitMode) {            return UIInterfaceOrientationMaskPortrait;        }else{             return UIInterfaceOrientationMaskLandscape;        } }-(BOOL)shouldAutorotate{   if (_isPortraitMode) {        return NO;    }else{        return YES;     }}-(void)setIsPortraitMode:(BOOL)isPortraitMode{    DLog();    _isPortraitMode=isPortraitMode;    __strongUIViewController * strSelf = self;    __strongUIViewController   * strFatherViewController =self.presentingViewController;    [strFatherViewController dismissViewControllerAnimated:NOcompletion:nil];    [strFatherViewController presentViewController:strSelfanimated:NOcompletion:nil];     if (isPortraitMode==YES) {        self.view.bounds=CGRectMake(0,0, Dev_ScreenWidth,Dev_ScreenHeight);    }else{        //        self.view.bounds=CGRectMake(0,0, Dev_ScreenHeight,Dev_ScreenWidth);    }}


0 0