Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8739173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:52:46+00:00 2026-06-13T10:52:46+00:00

I have a UIViewController that contains other ViewControllers. Initial ViewController is set in viewDidLoad:

  • 0

I have a UIViewController that contains other ViewControllers. Initial ViewController is set in viewDidLoad:

FirstViewController *first = [FirstViewController alloc] init];
first.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
first.view.frame = m_content.frame;

[self addChildViewController:first];
[m_content.view addSubview:first.view];
[first didMoveToParentViewController:self];
m_activeViewController = first;

This Container Controller has implemented automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers to return YES. It has also implemented to manualy forward rotation changes to non active ViewControllers

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    for(UIViewController *vc in m_viewControllers)
    {
        if(vc != [m_activeViewController]
            [vc willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    }
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    for(UIViewController *vc in m_viewControllers)
    {
        if(vc != [m_activeViewController]
            [vc didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    }
}

When menu button is tapped i make the transition between ViewControllers.

- (void)onMenuItemTapped:(id)sender
{
    UIViewController *vc = [m_viewControllers objectAtIndex:sender.tag];

    vc.view.frame = m_content.frame;
    [self addChildViewController:vc];
    [self transitionFromViewController:m_activeViewController toViewController:vc duration:0 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished) {
    [vc didMoveToParentViewController:self];
    [m_activeViewController removeFromParentViewController];
    m_activeViewController = vc;
    }];
}

This transition works fine for my “normal” ViewControllers and they are displayed properly after orientation changes, even if they are not active. However, one of these Child View Controllers, called SecondCV, has UIPageViewController as a Child View Controller. I have UIPageViewControllerDelegate and UIPageViewControllerDataSource set to this SecondCV and in pageViewController:spineLocationForInterfaceOrientation: I return UIPageViewControllerSpineLocationMin for Portrait and UIPageViewControllerSpineLocationMid for Landscape. Rotation for this SecondVC works correctly when its active – there are two pages on the landscape and one on the portrait mode displayed correctly. But when this SecondVC is not active the rotation is incorrect. Even if pageViewController:spineLocationForInterfaceOrientation: is called, there is still one page in both Portrait and Landscape mode. I am trying to fix this for some time, but i dont see any other options. Do you have any ideas how to fix this?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:52:48+00:00Added an answer on June 13, 2026 at 10:52 am

    I have solved this kind of tricky.

    Actually the SecondVC was rotated correctly, or at least, spine location was changed correctly. So when I have rotated the device and the SecondVC was not active view controller in parent view, it HAS received rotation messages and pageViewController:spineLocationForInterfaceOrientation: was called also. I set the correct spine location for new interface orientation and called setViewControllers to SecondVC’s page view controller. Problem was, that even if i set two view controller for UIPageViewControllerSpineLocationMid, after displaying SecondVC there was still just one, like in UIPageViewControllerSpineLocationMin.

    I have “fixed” the problem, by setting view controllers to page view controller in viewWillAppear: again, because when this method is called, spine location for page view controller is correct and based on this information i set one, or two pages (view controllers)

    - (void)viewWillAppear:(BOOL)animated
    {
    if(m_pageController.spineLocation == UIPageViewControllerSpineLocationMid)
    {
        LeftPageController *left;
        RightPageController *right;
        if(m_pageController.viewControllers.count > 0)
        {
            left = [m_pageController.viewControllers objectAtIndex:0];
    
            right = [m_storyboard instantiateViewControllerWithIdentifier:@"rightPage"];
            [right loadView];
        }
    
        [m_pageController setViewControllers:[NSArray arrayWithObjects:left, right, nil] direction:UIPageViewControllerNavigationDirectionForward | UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
    
        [m_left hideGallery];
    }
    
    if(m_pageController.spineLocation == UIPageViewControllerSpineLocationMin)
    {
    
        [m_pageController setViewControllers:[NSArray arrayWithObject:[m_pageController.viewControllers objectAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward | UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
    }
    
    [super viewWillAppear:animated];
    }
    
    
    - (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
    {
    if(UIInterfaceOrientationIsPortrait(orientation))
    {
        LeftPageController *left = [pageViewController.viewControllers objectAtIndex:0];
        [pageViewController setViewControllers:[NSArray arrayWithObject:left] direction:UIPageViewControllerNavigationDirectionForward | UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
    
        pageViewController.doubleSided = NO;     
    
        return UIPageViewControllerSpineLocationMin;
    }
    
    if(UIInterfaceOrientationIsLandscape(orientation))
    {    
        LeftPageController *left;
        RightPageController *right;
        if(pageViewController.viewControllers.count > 0)
        {
            left = [pageViewController.viewControllers objectAtIndex:0];
            right = [m_storyboard instantiateViewControllerWithIdentifier:@"rightPage"];
            [right loadView];
        }
    
        [pageViewController setViewControllers:[NSArray arrayWithObjects:left,right, nil] direction:UIPageViewControllerNavigationDirectionForward | UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
    
        return UIPageViewControllerSpineLocationMid;
    }
    
    return UIPageViewControllerSpineLocationMin;
    }
    

    I know i am doing the same thing twice, but thats the price i am willing to pay in this case. Why after calling pageViewController:spineLocationForInterfaceOrientation: and setting two view controllers for Landscape, when SecondVC is inactive, is only one ViewController in m_pageController in viewWillAppear: after activating SecondVC stays a mystery for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First a little background info: I have UIViewController that contains a UITableView. In the
I have a UIViewController that contains UITextField . I set the inputAccessory of the
I have differents UIViewController that contains components that appear and disappear from the view
I have a UIViewController that contains a subview and a UIToolbar. I'm trying to
I have a problem with data in UITableView. I have UIViewController, that contains UITableView
I have a custom UIViewController subclass that handles all the view initialization by itself
I have a UIPopOverController that shows a UIViewController with a UITableview in its view.
Following Scenario: I have a = UIViewController A that contains a UIScrollView I have
In my App I have an UIViewController, that pushed by another ViewController's navigation controller.
I have a view that contains a UIScrollView. The UIScrollView contains an UIImageView (only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.