我有一个奇怪的问题。我有一个拆分视图控制器,在详细视图中我有一个滚动视图。在滚动视图中,我有一些信息。
当应用程序首次以横向打开时,滚动视图始终位于详细视图视图的下方1/2。当我触摸根视图中的项目并显示下一个视图时,我将返回滚动视图,滚动视图位于正确的位置(10,10)。
我在详细视图的viewWillAppear方法中设置了滚动视图的框架。这是我的代码:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) ||
([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)) {
[self setPortrait];
CGRect tmpR = [self.view frame];
NSLog(@"The Detail View Controller Portrait view: width: %f height: %f",tmpR.size.width, tmpR.size.height);
} else {
[self setLandscape];
CGRect tmpR = [self.view frame];
NSLog(@"The Detail View Controller Portrait view: width: %f height: %f",tmpR.size.width, tmpR.size.height);
}
// show the front page message....
[self setMessage:kDetailViewMessage];
// make sure the scroll is at the top....
[scrollView setContentOffset:CGPointMake(0, 0)];
}
-(void)setLandscape {
// set the proper scroll view size...
CGRect navigationBarFrame = self.navigationController.navigationBar.frame;
CGRect detailWindowFrame = splitView.detailViewController.view.frame;
CGRect sframe = CGRectZero;
sframe.origin = CGPointMake(10, 10 + navigationBarFrame.size.height);
sframe.size = CGSizeMake(detailWindowFrame.size.width - 20, detailWindowFrame.size.height - 20);
[self.scrollView setFrame:sframe];
[detailDescriptionLabel setFrame:CGRectMake(0, 0, sframe.size.width, sframe.size.height)];
[detailDescriptionLabel sizeToFit];
}
现在,应用程序将仅以横向显示,并且不会调用setPortrait函数。
这让我疯狂了好几个小时.....任何想法?
答案 0 :(得分:0)
我认为您需要设置内容视图的边界原点,而不是框架。 (无论如何,这就是它对NSScrollView的作用。)