UIScrollView placement on master view of a split view controller
I am having a weird issue. I have a split view controller and in the detail view I have a scroll view. Inside the scroll view I have a lavel with some information.
When the application first opens in landscape开发者_如何学JAVA, the scroll view is always placed 1/2 way down the view of the detail view. When I touch an item in the root view and the next view shows, then I return to the scroll view, the scroll view is in the correct place (10,10).
I have set the frame of the scroll view in the viewWillAppear method of the detail view. Here is my code:
- (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];
}
Right now the application will only display in landscape and the setPortrait function is not called.
This has been driving me crazy for a few hours now..... Any ideas?
I think you need to set the bounds origin of the content view, not the frame. (That's how it works for NSScrollView, anyway.)
精彩评论