Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8 Modal ViewController Rotation issue

Hi I have a problem with rotation of an Modal presented ViewController in iOS8. All this works fine on iOS7 and lower.

App Struct:

  • RootController (supported Orientation: Portrait)
  • Modal Presented ViewController (supported Orientation: All)

My Problem is when I Rotate the Device when the Modal Controller is Presented the view of the Modal Controller didn't resize to the lanscape frame.

Looks like so:

enter image description here The Rotation methods was called and when I set the frame of the view to Landscape manually the user interaction of the right side (screen gray side) didn't work.

RootController code:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger) supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

Modal Controller code:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}


- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                         duration:(NSTimeInterval)duration
{
    if (self.presentingViewController != nil) {
        [self.presentingViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation
                                                                        duration:duration];
    }
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                duration:(NSTimeInterval)duration
{
    if (self.presentingViewController != nil) {
        [self.presentingViewController willRotateToInterfaceOrientation:toInterfaceOrientation
                                                               duration:duration];
    }
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    if (self.presentingViewController != nil) {
        [self.presentingViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    }
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {

    } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {

    }];
}

Can any one help me to fix this problem for iOS8.

like image 427
Zeropointer Avatar asked Oct 01 '14 13:10

Zeropointer


1 Answers

How are you presenting the modal view controller? Why are you forwarding the rotation methods yourself? When done properly, this should be handled automatically and all you need are the -supportedInterfaceOrientations methods (and as Jasper notes, the autoresizingMask, or Auto Layout constraints, need to be correct).

like image 84
Ricky Avatar answered Oct 31 '22 01:10

Ricky