亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

iOS 6迫使設備朝向橫向

iOS 6迫使設備朝向橫向

侃侃無極 2019-11-23 11:04:38
我給了一個帶有10個視圖控制器的應用程序。我使用導航控制器加載/卸載它們。除了一個以外,其他所有設備都處于縱向模式。假設第7個VC處于橫向狀態。我需要在加載時以橫向顯示它。請提出一種在IOS 6中強制將方向從縱向更改為橫向的方法(在IOS 5中也同樣適用)。這是我在 IOS 6 之前所做的事情:- (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated];    UIViewController *c = [[[UIViewController alloc]init] autorelease];    [self presentModalViewController:c animated:NO];    [self dismissModalViewControllerAnimated:NO];}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return (interfaceOrientation == UIInterfaceOrientationPortrait);}呈現和消除模態VC迫使該應用檢查其方向,因此shouldAutorotateToInterfaceOrientation被人們稱為。我在IOS 6中嘗試過的方法:- (BOOL)shouldAutorotate{    return YES;}-(NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskLandscape;}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{    return UIInterfaceOrientationLandscapeLeft;}加載時,控制器保持縱向狀態。旋轉設備后,方向更改就可以了。但是我需要使控制器自動旋轉以在負載時橫向顯示,因此用戶將不得不旋轉設備才能正確查看數據。另一個問題:將設備旋轉回縱向后,方向變為縱向,盡管我supportedInterfaceOrientations僅在中指定了UIInterfaceOrientationMaskLandscape。為什么會發生?此外,無上述3種方法越來越被調用。一些(有用的)數據:在我的plist文件中,我指定了3個方向-除了上下顛倒外,其他所有方向。該項目是從Xcode 4.3 IOS 5開始的。包括xibs在內的所有類都是在Xcode 4.5 IOS 6之前創建的,現在我使用的是最新版本。在plist文件中,狀態欄設置為可見。在xib文件中(我要在橫向文件中),狀態欄為“無”,方向設置為橫向。任何幫助表示贊賞。謝謝。iPhone Objective-C 方向 ios6
查看完整描述

3 回答

?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

這應該可以工作,類似于iOS 6之前的版本,但帶有UINavigationController:


UIViewController *portraitViewController = [[UIViewController alloc] init];

UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:portraitViewController];

[self.navigationController presentModalViewController:nc animated:NO];

[self.navigationController dismissModalViewControllerAnimated:NO];

我先打這個,再推下一個UIViewController。UIViewController即使當前UIViewController處于橫向模式,它也會強制將下一個按下的按鈕顯示為縱向模式(也適用于縱向到橫向)。適用于iOS 4 + 5 + 6。


查看完整回答
反對 回復 2019-11-23
?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

我認為最好的解決方案是堅持使用Apple官方文檔。因此,據此我使用以下方法,并且在iOS 5和6上一切正常。在我的VC中,我重寫了以下方法:


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    // Return YES for supported orientations

    return UIInterfaceOrientationIsPortrait(interfaceOrientation);

}

適用于iOS 6的方法,第一種方法返回支持的方向遮罩(如其名稱所示)


-(NSUInteger)supportedInterfaceOrientations{


    return UIInterfaceOrientationMaskPortrait;

}

第二個告訴您的VC,當要顯示VC時,這是首選的界面方向。


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

    return UIInterfaceOrientationPortrait;

}

只需將Portrait更改為所需的方向即可;)此解決方案運行流暢,我不喜歡圍繞此簡單解決方案創建宏和其他內容的想法。希望能有所幫助...


查看完整回答
反對 回復 2019-11-23
  • 3 回答
  • 0 關注
  • 659 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號