Search code examples
iosios6uiscrollviewios7

setFrame working on iOS7 but not anymore on iOS6


I just switched to iOS7 SDK. My app worked fine before this on iOS6 but not anymore except it works fine on iOS7 now.

I have a scrollView with page control to show 3 different tabs with the following settings:

self.scrollView.pagingEnabled = YES;
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * 3, self.scrollView.frame.size.height);
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.scrollsToTop = NO;
self.scrollView.delegate = self;

I add on this scrollView my 3 views which I load from 3 different storyboards:

    UIStoryboard *timelineStoryboard=[UIStoryboard storyboardWithName:@"timelineStoryboard" bundle:nil];
TabBarViewController *mainVC=[timelineStoryboard instantiateInitialViewController];
self.currentViewController =mainVC;
[mainVC.view setFrame:CGRectMake(320, 20, mainVC.view.frame.size.width, mainVC.view.frame.size.height)];
[self.scrollView addSubview:mainVC.view];
[self addChildViewController:mainVC]; 

UIStoryboard *expenseStoryboard=[UIStoryboard storyboardWithName:@"expenseStoryboard" bundle:nil];
TabBarViewController *leftVC=[expenseStoryboard instantiateInitialViewController];
self.leftViewController =leftVC;
[leftVC.view setFrame:CGRectMake(0, 20, leftVC.view.frame.size.width, leftVC.view.frame.size.height)];
[self.leftViewController.view setFrame:CGRectMake(0, 20, leftVC.view.frame.size.width, leftVC.view.frame.size.height)];
[self.scrollView addSubview:leftVC.view];
[self addChildViewController:leftVC];


UIStoryboard *dashboardStoryboard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
TabBarViewController *rightVC=[dashboardStoryboard instantiateViewControllerWithIdentifier:@"dashboardVC"];
self.leftViewController =rightVC;
[rightVC.view setFrame:CGRectMake(640, 20, rightVC.view.frame.size.width, rightVC.view.frame.size.height)];
[self.scrollView addSubview:rightVC.view];
[self addChildViewController:rightVC];

On iOS6, these 3 views are display on top of each other whereas on iOS7 they are correctly displayed (on with abscissa 0, one with x=320 and another one with x=640). Does anyone have any idea on how to fix this?

Many thanks


Solution

  • I found the answer. I used intermediary variables and it worked. Don't why though. If anyone has the answer, I'd be glad to hear it.

    Anyway, the code which worked is here:

    UIStoryboard *dashboardStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    TabBarViewController  *rightVC = [dashboardStoryboard instantiateViewControllerWithIdentifier:@"dashboardVC"];
    
    UIView *dashboardView = rightVC.view;
    [dashboardView setFrame:CGRectMake(640,
                                       20,
                                       320,
                                       screenHeight+20)];
    
    [self.scrollView addSubview:dashboardView];
    [self addChildViewController:rightVC];