Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does didRotateFromInterfaceOrientation in a category cause issues with UISplitView?

I have a tabbed app with a a UISplitView in one of the tabs.

I'm using UITabBarController+iAds and have an issue which the dev has so far not been able to solve.

Unfortunately, this is what my UI looks like on rotation of the iPad:

enter image description hereenter image description here

The category is called from within AppDelegate and the following code is used to refresh the ad when the device is rotated:

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

As I understand it, this is preventing the MasterViewController from working correctly but I don't fully understand the principle behind the cascading of method calls to understand how to fix this issue.

like image 857
Leon Avatar asked Sep 23 '14 16:09

Leon


1 Answers

Here's what the Apple Developer Guide says about the didRotateFromInterfaceOrientation method:

Subclasses may override this method to perform additional actions immediately after the rotation.

...

Your implementation of this method must call super at some point during its execution.

My best guess is that certain drawing operations in the view controller doesn't happen because you're not calling the superclass method from your implementation. Try to fix it like this:

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

UPDATE: On iOS 8 this method is deprecated and no longer called when the device is rotated. Instead you need to use a new method:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    NSLog(@"Szie changed");
    [self layoutBanner];
}
like image 51
Bedford Avatar answered Oct 05 '22 01:10

Bedford