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

UINavigationController 強(qiáng)制旋轉(zhuǎn)

UINavigationController Force Rotate(UINavigationController 強(qiáng)制旋轉(zhuǎn))
本文介紹了UINavigationController 強(qiáng)制旋轉(zhuǎn)的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我的應(yīng)用程序主要是縱向的,但是有一個(gè)視圖需要橫向.

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

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

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

除了一個(gè)之外的所有 UIViewControllers 都有這個(gè):

All UIViewControllers except one have this:

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

需要 Landscape 的 UIViewController 有這個(gè):

The UIViewController that requires Landscape has this:

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

現(xiàn)在,當(dāng)用戶到達(dá)橫向 UIViewController 時(shí),它會(huì)以縱向顯示.然后,用戶可以旋轉(zhuǎn)他們的手機(jī),它會(huì)按照我的意愿橫向顯示(鎖定為橫向).然后用戶繼續(xù)使用縱向 UIViewController,同樣的情況發(fā)生:它從橫向開始,然后他們旋轉(zhuǎn)手機(jī),它再次變成縱向(并鎖定為縱向).

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 之間似乎允許方向鎖定,但是自動(dòng)旋轉(zhuǎn)/以編程方式更改方向被某種方式阻止了.

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

如何強(qiáng)制手機(jī)更新到正確的方向?

有一個(gè)臨時(shí)解決方案:我可以檢測設(shè)備的方向并顯示一條消息,要求他們?cè)诓徽_時(shí)旋轉(zhuǎn)設(shè)備,但這不是最佳選擇.

推薦答案

我的一個(gè)應(yīng)用程序也有同樣的要求?。?!

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

幸運(yùn)的是我找到了解決方案!

luckily I found a solution!

為了保持主視圖控制器的橫向,無論從哪個(gè)方向彈出/推送,我都做了以下事情:(在 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 上,先前的答案導(dǎo)致屏幕閃爍,而且 - 它不穩(wěn)定(在某些情況下它不再適合我.)所以,為了我的需要,我將代碼更改為:(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.

希望它會(huì)有所幫助!

這篇關(guān)于UINavigationController 強(qiáng)制旋轉(zhuǎn)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Using Instruments to test an iOS app without having source code to the application(在沒有應(yīng)用程序源代碼的情況下使用 Instruments 測試 iOS 應(yīng)用程序)
KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動(dòng)運(yùn)行/壓力測試 iOS 應(yīng)用程序以找出罕見 UI 錯(cuò)誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標(biāo)成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態(tài)和動(dòng)態(tài)單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級(jí)到 Xcode 4.5 后,iOS 5 SDK 消失了)
主站蜘蛛池模板: 国产美女久久 | 性高湖久久久久久久久 | 在线亚洲免费视频 | 人人干免费 | 欧美国产日韩在线 | 国产一区二区三区四区在线观看 | 国产精品成人一区二区三区 | 亚洲国产精品日韩av不卡在线 | 欧美在线观看一区 | 国产精品免费观看 | 成人在线视频免费观看 | 亚洲精品在线看 | 97国产成人 | 黄色国产在线播放 | 国产精品视频一区二区三区 | 在线欧美日韩 | 国产美女h视频 | 久久精品亚洲精品国产欧美 | 超碰520| 日本色婷婷 | 国产免费观看一级国产 | 国产精品久久二区 | 色综合色综合 | 国产精品久久久久久模特 | 亚洲国产成人久久综合一区,久久久国产99 | 欧美精品在线一区二区三区 | 国产精品久久国产精品 | 免费一级黄色 | 国产精品久久久久久吹潮 | 国产免费麻豆视频 | 久久新| 中文字幕视频在线观看 | 日韩欧美国产精品综合嫩v 一区中文字幕 | 亚洲美女在线视频 | 亚洲欧美日韩精品久久亚洲区 | 伊人在线 | 国产乱码精品一区二区三区五月婷 | 日本亚洲欧美 | 亚洲欧美视频一区二区 | 99精品欧美一区二区三区综合在线 | 成人免费视频在线观看 |