1

I'm working on a CatalogueViewController that contains a scroll view that is programmatically filled with a sequence of PageViewController. It's old code, where everything is built programmatically for iPad for only portrait view. Also the content of each PageVC is built programmatically, and some custom UIView are added programmatically at runtime (this means that each view created and inserted in the VC has hard-coded frame).

Now I need to enable landscape mode view, so each page should now be "autoresized" in order to fill an half of the iPad screen (so I can see 2 pages at time in landscape and 1 page in portrait).

I studied a lot of links about autoresizing, as this, this and this, among all.

I though then that a working solution could have been to insert the following code in the -(void)viewDidLoad, -(void)viewWillAppear:(BOOL)animated, -(void)viewDidAppear:(BOOL)animated of my PageViewController

    [self.view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
    for(UIView* subview in self.view.subviews)
        [subview setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];

and (just to be sure) also the following in the main custom views (in many functions) that are added in the PageViewController (the ones that give to it its real visual structure)

    for(UIView* subview in self.subviews)
        [subview setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
    [self setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];

But it does not do the job... Please, note that CatalogueViewController has NOT autolayout active, PageViewController does not have a xib and each big custom view (as I said, added in the page view in order to give the main structure to the PageViewController) has a xib with autolayout NOT active.

I do not understand what's the difference in

  1. having autolayout active or not in the my PageViewController (the VC inside the scroll view, which is inside the CatalogueViewController)? I think should not be active, but I do not know why
  2. setting autoresizingmask before or after assign a frame to a subview that will be added into the PageViewController?

for the point 2, please note that when a PageViewController is allocated (but it is still empty) I apply to it a frame that is the correct one (full page or halfpage) depending on the device orientation and that after a rotation I re-fix the frame of each PageViewController.

thanks a lot to anyone in advance

Community
  • 1
  • 1
ddb
  • 2,423
  • 7
  • 28
  • 38

0 Answers0