5

我在其中一個選項卡中有一個帶有UISplitView的選項卡式應用程序。爲什麼類別中的didRotateFromInterfaceOrientation會導致UISplitView出現問題?

我正在使用UITabBarController+iAds,並且存在開發人員迄今無法解決的問題。

不幸的是,這是我的UI看起來像在iPad上的旋轉:

enter image description here enter image description here

類別是從內部AppDelegate中調用,下面的代碼是用來刷新的廣告時,該設備被旋轉:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    NSLog(@"Did rotate"); 
    [self layoutBanner]; 
} 

據我所知,這是阻止MasterViewController正常工作,但我不完全理解背後的原則方法調用的級聯以瞭解如何解決此問題。

+0

會發生什麼事,如果你不叫'[自layoutBanner]' ? – 2014-09-25 16:57:09

+0

問題仍然出現,但廣告橫幅未重新加載。 – Leon 2014-09-25 17:11:03

回答

7

這裏的蘋果開發者指南說,關於didRotateFromInterfaceOrientation方法是什麼:

子類可以重寫此方法,旋轉後立即執行其他操作 。

...

此方法的實現必須在其執行過程中的一些點 調用super。

我最好的猜測是,在視圖控制器的某些繪圖操作不會發生,因爲你不是要求您實現超類方法。嘗試修復它是這樣的:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    NSLog(@"Did rotate"); 
    [self layoutBanner]; 
} 

UPDATE: 在iOS 8此方法已被棄用,不再當裝置旋轉時調用。相反,你需要用一種新的方法:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator 
{ 
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; 
    NSLog(@"Szie changed"); 
    [self layoutBanner]; 
} 
+0

我敢肯定,我嘗試過這一點,但沒有奏效。但是,自iOS 8以來,我無法重試,因爲在iOS 8設備上沒有調用RotateFromInterfaceOrientation。這似乎是一個問題,而不是ViewControllers。 – Leon 2014-09-29 17:15:49

+0

原因是Apple在iOS 8中棄用了它。我更新了我的答案以反映這一點。 – Bedford 2014-10-02 17:47:34

+0

好的這個工作,它不會遭受截圖中的問題。現在我只需要修復其餘的代碼。謝謝! – Leon 2014-10-03 20:56:47

相關問題