2

我刚刚切换到 iOS7 SDK。我的应用程序在此之前在 iOS6 上运行良好,但现在在 iOS7 上运行良好。

我有一个带有页面控件的 scrollView 来显示具有以下设置的 3 个不同的选项卡:

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;

我在这个 scrollView 上添加了我从 3 个不同的故事板加载的 3 个视图:

    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];

在 iOS6 上,这 3 个视图彼此重叠显示,而在 iOS7 上,它们正确显示(横坐标为 0,一个 x=320,另一个 x=640)。有谁知道如何解决这个问题?

非常感谢

4

1 回答 1

0

我找到了答案。我使用了中间变量并且它起作用了。不要为什么。如果有人有答案,我会很高兴听到它。

无论如何,有效的代码在这里:

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];
于 2013-09-24T19:42:19.330 回答