2

这是一个有趣的问题。在 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,但它实际上是在屏幕中间的某个地方!

有人知道这里发生了什么吗?

4

1 回答 1

0

我会说这是因为框架被设置为 iPhone 框架的顶部(因此距离底部 320 像素),然后视图被调整大小以适应 iPad 屏幕。然而 UIToolbar 默认设置为粘在窗口的底部(固定的下边距和灵活的上边距),因此它与底部保持 320px 的距离。

要解决此问题,请尝试:

[self.aToolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin];

在设置工具栏的框架之前(如果在设置框架之前不起作用,请尝试将其放在之后)

于 2011-03-22T00:28:51.983 回答