0

I have this code which works fine except for if you enter the view controller from portrait then it stays in portrait. I need it once it goes to the view controller to go to landscape and stay in landscape.

- (NSUInteger)supportedInterfaceOrientations {
    if (self.isFlexiGram) {
        return UIInterfaceOrientationMaskLandscape;
    } else {
        return UIInterfaceOrientationMaskAll;
    }

}

- (BOOL)shouldAutorotate {
    return YES;
}

I'm changing my container view controller with the following methods

#pragma mark - Container Controller Methods
- (void)presentDetailController:(UIViewController*)detailVC{

    //0. Remove the current Detail View Controller showed
    if(self.currentDetailViewController){
        [self removeCurrentDetailViewController];
    }

    //1. Add the detail controller as child of the container
    [self addChildViewController:detailVC];

    //2. Define the detail controller's view size
    detailVC.view.frame = [self frameForDetailController];

    //3. Add the Detail controller's view to the Container's detail view and save a reference to the detail View Controller
    [self.containerView addSubview:detailVC.view];
    self.currentDetailViewController = detailVC;

    //4. Complete the add flow calling the function didMoveToParentViewController
    [detailVC didMoveToParentViewController:self];
}

- (void)removeCurrentDetailViewController{

    //1. Call the willMoveToParentViewController with nil
    //   This is the last method where your detailViewController can perform some operations before neing removed
    [self.currentDetailViewController willMoveToParentViewController:nil];

    //2. Remove the DetailViewController's view from the Container
    [self.currentDetailViewController.view removeFromSuperview];

    //3. Update the hierarchy"
    //   Automatically the method didMoveToParentViewController: will be called on the detailViewController)
    [self.currentDetailViewController removeFromParentViewController];
}

I've tried the preferredInterfaceOrientationForPresentation but that doesn't get called because I'm not using presentViewController.

I've tried the following questions

Forcing UIInterfaceOrientation changes on iPhone IOS 6 force device orientation to landscape

I've also gone through apple documentation

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html

Community
  • 1
  • 1
user1898829
  • 3,437
  • 6
  • 34
  • 62
  • is it the whole app that is just landscape or just this view? you can tick on and off interface orientations in the project settings, (not sure how much you have done with orientation, this may be to basic). If you un-ticked up and down portrait it would never go to that orientation as you indicate it's not supported. – LanternMike May 01 '14 at 13:52
  • The whole app needs to be all orientations but a specific view needs to be in landscape only. – user1898829 May 02 '14 at 13:27

0 Answers0