阻止 UIToolbar 在横向方向上消失 - iPad

发布于 2024-10-20 17:54:12 字数 119 浏览 4 评论 0原文

不确定为什么会发生这种情况或如何阻止它,详细信息 viewcontroller 上的 UIToolBar 仅在纵向视图期间可见。我希望它在所有方向都可见。我该怎么做?谢谢。

Not sure why this happens or how to stop it, my UIToolBar on the details viewcontroller is only visible during portrait view. I want it visible at all orientations. How do I do that? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

神爱温柔 2024-10-27 17:54:12

我遇到了同样的问题,只需将 UIToolBar 拖到我的视图上并将其停靠在窗口顶部即可。它以横向显示,但不以纵向显示。 Interface Builder - 至少是嵌入在 Xcode 4 中的那个 - 似乎没有对调整大小蒙版做正确的事情。

虽然 Kshitiz 的上述答案可行,但它有一些缺陷。根据编码,它不支持所有四个方向。更重要的是,它与分辨率无关。

enamrik 的评论中简要描述了更好的解决方案,因此应归功于他/她。步骤如下:

  1. 选择 Interface Builder 中的工具栏。
  2. 打开尺寸检查器。
  3. 在“自动调整大小”框中,选择正方形外部的左侧、右侧和顶部“工字梁”。当调整视图大小时,这会保持工具栏相对于视图两侧的位置固定。
  4. 在“自动调整大小”方块内,选择两端带有箭头的水平线。这会导致工具栏的大小与父视图同步变化。

I encountered the same problem by just dragging a UIToolBar on to my view and docking it on the top of the window. It showed up in landscape but not portrait. Interface Builder - at least the one embedded in Xcode 4 - doesn't seem to do the right thing with the resize masks.

While Kshitiz's answer above will work, it has a couple of flaws. As coded, it does not support all four orientations. More importantly, it's not resolution independent.

A better solution is briefly described in enamrik's comment, so credit should go to him/her. Here are the steps:

  1. Select the tool bar in Interface Builder.
  2. Open the Size inspector.
  3. In the Autosizing box, select the left, right and top "i-beams" on the exterior of the square. This keeps the position of the toolbar fixed relative to the sides of the view when the view is resized.
  4. Inside the Autosizing square, select the horizontal line with arrows on both ends. This causes the size of the toolbar to change in sync with the parent view.
动听の歌 2024-10-27 17:54:12

在你的视图控制器的这个功能中重置视图框架兄弟

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Override to allow orientations other than the default portrait orientation.
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
        self.view.frame = CGRectMake(0, 0, 703,768);    

        } else {
        self.view.frame = CGRectMake(0, 0, 768, 1024);
        }


    return YES;
}

和你的工具栏框架
祝你好运

in your this function of view controller reset view frame bro

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Override to allow orientations other than the default portrait orientation.
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
        self.view.frame = CGRectMake(0, 0, 703,768);    

        } else {
        self.view.frame = CGRectMake(0, 0, 768, 1024);
        }


    return YES;
}

and your tool bar frame too
good luck

指尖凝香 2024-10-27 17:54:12

当我以编程方式添加 UIPickerView 并为 PickerView 添加 UIToolBar 时,遇到了同样的问题。只需要为 UIPickerView 添加 [.flexibleWidth,.flexibleHeight] 即可。例如:-

let statTypePicker = UIPickerView()

然后添加

 self.statTypePicker.autoresizingMask = [.flexibleWidth,.flexibleHeight]

Faced the same problem when I add UIPickerView programmatically and add UIToolBar for the PickerView. Just need to add [.flexibleWidth,.flexibleHeight] for the UIPickerView. eg:-

let statTypePicker = UIPickerView()

And then add

 self.statTypePicker.autoresizingMask = [.flexibleWidth,.flexibleHeight]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文