久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

UINavigationController 強制旋轉

UINavigationController Force Rotate(UINavigationController 強制旋轉)
本文介紹了UINavigationController 強制旋轉的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我的應用程序主要是縱向的,但是有一個視圖需要橫向.

My application is primarily portrait, however there is one view that REQUIRES a landscape orientation.

我的視圖包含在 UINavigationController 中,這(顯然)是導致此問題的原因.

My views are contained within a UINavigationController, which (apparently) is the cause of this issue.

除了一個之外的所有 UIViewControllers 都有這個:

All UIViewControllers except one have this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

需要 Landscape 的 UIViewController 有這個:

The UIViewController that requires Landscape has this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

現在,當用戶到達橫向 UIViewController 時,它會以縱向顯示.然后,用戶可以旋轉他們的手機,它會按照我的意愿橫向顯示(鎖定為橫向).然后用戶繼續使用縱向 UIViewController,同樣的情況發生:它從橫向開始,然后他們旋轉手機,它再次變成縱向(并鎖定為縱向).

Now, what happens is when the user reaches the landscape UIViewController, it is shown in portrait. The user can then rotate their phone and it displays in landscape as I want it to (locking to landscape). The user then progresses onwards to a portrait UIViewController and the same happens: it start in landscape, then they rotate their phone and it becomes portrait again (and locks to portrait).

UIViewController 之間似乎允許方向鎖定,但是自動旋轉/以編程方式更改方向被某種方式阻止了.

It seems orientation locking is allowed between UIViewControllers, however auto-rotation / programmatically changing the orientation is somehow blocked.

如何強制手機更新到正確的方向?

有一個臨時解決方案:我可以檢測設備的方向并顯示一條消息,要求他們在不正確時旋轉設備,但這不是最佳選擇.

推薦答案

我的一個應用程序也有同樣的要求?。?!

I had the same requirement for one of my applications!!!

幸運的是我找到了解決方案!

luckily I found a solution!

為了保持主視圖控制器的橫向,無論從哪個方向彈出/推送,我都做了以下事情:(在 viewWillAppear 中:)

//set statusbar to the desired rotation position
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];

//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[[UIViewController alloc] init] autorelease];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];

P.S.在 sdk 3.2.5 ios 5.0.1 上測試.

P.S.Tested on sdk 3.2.5 ios 5.0.1.

附:在 iOS 8 上,先前的答案導致屏幕閃爍,而且 - 它不穩定(在某些情況下它不再適合我.)所以,為了我的需要,我將代碼更改為:(ARC)

P.S. On iOS 8 previous answer results some screen flickering and also - it is not stable (In some cases It does not work for me anymore.) So, for my needs, I changed the code to: (ARC)

//set statusbar to the desired rotation position
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];

[self.navigationController presentViewController:[UIViewController new] animated:NO completion:^{
    dispatch_after(0, dispatch_get_main_queue(), ^{
        [self.navigationController dismissViewControllerAnimated:NO completion:nil];
    });
}];

//I added this code in viewDidDissapear on viewController class, which will be popped back.

希望它會有所幫助!

這篇關于UINavigationController 強制旋轉的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Using Instruments to test an iOS app without having source code to the application(在沒有應用程序源代碼的情況下使用 Instruments 測試 iOS 應用程序)
KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動運行/壓力測試 iOS 應用程序以找出罕見 UI 錯誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態和動態單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級到 Xcode 4.5 后,iOS 5 SDK 消失了)
主站蜘蛛池模板: 羞视频在线观看 | 免费看黄色小视频 | av免费观看网站 | 亚洲成色777777在线观看影院 | 亚洲日本中文字幕在线 | 日日艹夜夜艹 | 国产午夜精品久久 | 欧美日韩久 | 粉嫩粉嫩芽的虎白女18在线视频 | 人人种亚洲 | 国产一区二区三区久久久久久久久 | 在线高清免费观看视频 | 国产精品免费在线 | 999久久久 | 久久99久久 | 亚洲精品视频二区 | 人妖一区| 国产成人精品免高潮在线观看 | 精品乱子伦一区二区三区 | 日本不卡免费新一二三区 | 日韩欧美国产一区二区 | 欧美日韩高清一区二区三区 | 久久免费精品 | 亚洲一二三区在线观看 | 日批免费看 | 视频一区在线观看 | 日韩精品免费 | www.蜜桃av| 亚洲福利av | 亚洲免费在线观看视频 | 欧美精品一区二区三区在线播放 | 日韩电影中文字幕在线观看 | 亚洲精品日韩视频 | 婷婷五月色综合香五月 | 国产美女一区二区三区 | 9久久婷婷国产综合精品性色 | 欧美国产视频 | 国产在线精品一区 | 毛片一区二区 | 在线观看黄色电影 | 龙珠z在线观看 |