IOS app 開啟橫屏旋轉方法

手機橫屏固定顯示某個頁面

手機 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 上刪除

}

}


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容