这是一个有趣的问题。在 iPhone 上,我设置了一个视图,在屏幕底部有一个工具栏。我目前正在尝试将其作为一个通用应用程序,以便它也可以在 iPad 上运行。我希望工具栏位于 iPad 屏幕的顶部,因此在特定 viewController 的 viewDidLoad 方法中,我有以下代码。
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//move the toolbar to the top of the page and move the webview down by the height of the toolbar
CGRect toolBarFrame = self.aToolBar.frame;
CGRect webFrame = self.aWebView.frame;
webFrame.origin.y = toolBarFrame.size.height;
[self.aWebView setFrame:webFrame];
toolBarFrame.origin.y = 0;
[self.aToolBar setFrame:toolBarFrame];
[Utils errorString:[NSString stringWithFormat:@"origen: x=%f y=%f", self.aToolBar.frame.origin.x, self.aToolBar.frame.origin.y]];
[Utils errorString:[NSString stringWithFormat:@"origen: x=%f y=%f", self.aWebView.frame.origin.x, self.aWebView.frame.origin.y]];
}
我遇到的问题是 webView 向下移动很好,但工具栏只向上移动到似乎是 iPhone 屏幕的高度。对 errorString 的调用告诉我 webView 的原点在 0,44(它应该在的位置),工具栏的原点在 0,0,但它实际上是在屏幕中间的某个地方!
有人知道这里发生了什么吗?