为什么类别中的didRotateFromInterfaceOrientation会导致UISplitView出现问题?

时间:2014-09-23 16:38:18

标签: ios rotation uisplitviewcontroller objective-c-category screen-rotation

我有一个带标签的应用程序,其中一个标签中有一个UISplitView。

我使用UITabBarController+iAds并且遇到了开发人员目前无法解决的问题。

不幸的是,这就是我的UI在旋转iPad时的样子:

enter image description here enter image description here

从AppDelegate中调用该类别,以下代码用于在旋转设备时刷新广告:

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

据我了解,这阻止了MasterViewController正常工作,但我不完全理解级联方法调用背后的原理,以了解如何解决这个问题。

1 个答案:

答案 0 :(得分:7)

以下是Apple开发人员指南对didRotateFromInterfaceOrientation方法所说的内容:

  

子类可以覆盖此方法以执行其他操作   轮换后立即。

     

<强> ...

     

此方法的实现必须在某个时候调用super   在执行期间。

我最好的猜测是,视图控制器中的某些绘图操作不会发生,因为您没有从实现中调用超类方法。尝试解决这个问题:

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

<强>更新 在iOS 8上,不推荐使用此方法,并且在旋转设备时不再调用此方法。相反,您需要使用新方法:

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