这听起来可能是一个新手问题,但是我是 iOS 开发新手,
我的 iPad 视图上有 UIWebView 和 UITableView 。在shouldAutorotateToInterfaceOrientation
我调整它们的大小以获得像这样的漂亮外观。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if( interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
CGRect f = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 2);
self.mTextView.frame = f;
f = CGRectMake(0, self.view.frame.size.height / 2, self.view.frame.size.width, self.view.frame.size.height / 2);
self.mTableView.frame = f;
}
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
CGRect f = CGRectMake(0, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
self.mTextView.frame = f;
f = CGRectMake(self.view.frame.size.width / 2, 0, self.view.frame.size.width / 2, self.view.frame.size.height);
self.mTableView.frame = f;
}
return YES;
}
现在的问题:对于第一次加载,表格视图以正确的尺寸绘制,但是当我切换到纵向模式然后回到横向模式时,UITableView 变得比框架指定的更宽。那么为什么会发生这种情况以及如何解决这个问题?
PS。我还尝试以相同的方法为所有单元格设置框架并没有帮助。
PSS。这仅在设备上发生,在模拟器上 UITableView 正确显示