美文网首页IOS 那些事iOS Developer
IOS app 开启横屏旋转方法

IOS app 开启横屏旋转方法

作者: Hello_Kugou | 来源:发表于2016-11-03 20:26 被阅读434次

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

手机 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 上删除

}

}

相关文章

网友评论

    本文标题:IOS app 开启横屏旋转方法

    本文链接:https://www.haomeiwen.com/subject/zqriuttx.html