ios 横屏的时候显示固定的 vc(视图)

手机横屏固定显示某个页面

手机 app 开启横屏, 横屏的时候, 手机显示固定的页面, 不管app 在哪个页面横屏显示的始终是某个页面

 

方法:1

-(BOOL)shouldAutorotate{

return YES;

}

- (NSUInteger)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskAll;

}

注意该方法要写在控制器的根视图里才生效

2.通知: (要想在哪个页面都实现这种方法写在 APPdelegate 里)

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];

- (void)statusBarOrientationChange:(NSNotification *)notification{  UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

//在这个位置创建 view 或者 VC

if (orientation == UIInterfaceOrientationLandscapeRight) // home键靠右

{

//将 vc 或者 view 加到 window 上

}

if (orientation ==UIInterfaceOrientationLandscapeLeft) // home键靠左

{

//将 vc 或者 view 加到 window 上

}

if (orientation == UIInterfaceOrientationPortrait)

{

//将 vc 或者 view 从 window 上删除

}

if (orientation == UIInterfaceOrientationPortraitUpsideDown)

{

//将 vc 或者 view 从 window 上删除

}

}

 

posted @ 2016-11-03 20:31  验证码  阅读(279)  评论(0编辑  收藏  举报