iOS8 Modal ViewController not fires shouldAutoRotate.

205 Views Asked by At

I have a parentViewController that calls a modal ViewController with Delegate UITableViewController. The problem is that I do not have navigation stack to get the value from the parent's shouldAUtoRotate.

Since the shouldAutorotate never fired it gets it from a main controller where return NO and this cannot be changed. Is there a way to manipulate the modal controller to get the proper shouldAutorotate set to YES?

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.pv dismiss:YES];
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
            //[self fullScreenAction:nil];
        } else {
//            [self exitFullScreenAction:nil];
        }
    }
}
-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
}

//ios >=6
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ||
    (interfaceOrientation == UIInterfaceOrientationPortrait) ||
    (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
    (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
1

There are 1 best solutions below

0
ReaLity On

I managed to solve my problem although is not the best solution, maybe for some will be useful.

So i create a new Category Controller in order to use it to set manually the Rotation calls.

.m

#import "UINavigationController+AutoRotate.h"

@implementation UINavigationController (AutoRotate)

- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationMaskAll;
}
@end

and .h

#import <UIKit/UIKit.h>

@interface UINavigationController (AutoRotate)

- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

@end

And then the Modal was working as it should without a navigation controller.