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

相关问题