IOS Custom Container VC and children requiring specific orientation

I've tried many ways to find an answer to this problem, but a lot of what I see is mostly blocking rotation issues with UINavigationController

in the root view controller.

In my project, I have a custom one UIViewController

using the Containment View Controller. I haven't implemented methods -(BOOL)shouldAutomaticallyForwardAppearanceMethods

or -(BOOL)shouldAutomaticallyForwardRotationMethods

because they are default implementations that already return YES

. -(BOOL)shouldAutorotate

implemented and returned YES

.

The first display controller to show supports all orientations. This works as intended.

The second view controller, which is loaded instead of the first during the segue, has a conditional orientation. A view controller is essentially a view controller that contains UIPageViewController

PDF pages to display. Conditional orientation - PDF orientation. The method -(NSUInteger)supportedInterfaceOrientations

returns either UIInterfaceOrientationMaskLandscape

if the PDF is in landscape orientation or UIInterfaceOrientationMaskPortrait

if the PDF is in portait. This method has been called. However, during my session, I call:

[container transitionFromViewController:source 
           toViewController:dest 
           duration:1.0 
           options:UIViewAnimationOptionTransitionFlipFromRight 
           animations:^{} 
           completion:^(BOOL finished){/*relevant removal of vc from parents*/}];

      

The method calls my supported orientations but doesn't seem to apply them. I could use [[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:(__bridge id)(void *)[dest preferredInterfaceOrientationForPresentation];

, but this app can become a store, so I avoid that.

Any suggestions are greatly appreciated.

+3


source to share


1 answer


For the most part, UINavigationController answers should set you up. There is one trick that I have used in the past. In my parent VC, I am implementing the following methods:

- (UIViewController *)topViewController {
    return self.childViewControllers.lastObject;
}

- (BOOL)shouldAutorotate {
    return [[self topViewController] shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations {
    return [[self topViewController] supportedInterfaceOrientations];
}

      

This will work, but you need to rotate to a supported orientation before it respects the limitation of the second controller. The trick is to return NO - (BOOL)shouldAutorotate

until called viewDidAppear:

. Something like that:



- (BOOL)shouldAutorotate {
    return _viewDidShow ? YES : NO;
}

      

Then, before you call the transition method, call this:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];

      

0


source







All Articles