簡體   English   中英

僅在呈現viewcontroller之后才應調用shouldAutorotateToInterfaceOrientation

[英]shouldAutorotateToInterfaceOrientation is only called after presenting viewcontroller

當我創建一個項目並不加更改地啟動它並加載自動創建的viewcontroller時,它將調用shouldAutorotateToInterfaceOrientation,而不會出現任何問題。 現在,我嘗試了不同的方法來呈現自己的viewcontroller,但是在該視圖中,旋轉時不會調用shouldAutorotateToInterfaceOrientation。 我的第一個嘗試是以這種方式更改應用程序委托的didFinishLaunchingWithOptions:

ProjectView1 *pv1 = [ProjectView1 alloc];
self.viewController = pv1;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

但是在ProjectView1中,旋轉屏幕時不會調用shouldAutorotateToInterfaceOrientation。

我的第二次嘗試是加載通過創建項目創建的視圖,並通過調用presentModalViewController呈現我的自定義視圖模態,但是結果是我的自定義視圖控制器沒有調用shouldAutorotateToInterfaceOrientation。

在為UIViewController執行分配之后,應調用initWithNib方法。

我嘗試復制這種情況,以下代碼在方向更改時調用了shouldAutorotateToInterfaceOrientation:

 ProjectView1 *pv1 = [[ProjectView1 alloc]initWithNibName:nil bundle:nil];
 self.viewController = pv1;
 self.window.rootViewController = self.viewController;
 [self.window makeKeyAndVisible];

更改代碼以放置正確的nib文件名,或者如果您打算自己構建視圖,則將其保留為nil。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM