手機橫屏固定顯示某個頁面
手機 app 開啟橫屏, 橫屏的時候, 手機顯示固定的頁面, 不管app 在哪個頁面橫屏顯示的始終是某個頁面
方法:1
-(BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
注意該方法要寫在控制器的根視圖里才生效
2.通知: (要想在哪個頁面都實現(xiàn)這種方法寫在 APPdelegate 里)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
- (void)statusBarOrientationChange:(NSNotification *)notification{ ?UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
//在這個位置創(chuàng)建 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 上刪除
}
}