gpt4 book ai didi

objective-c - Objective-C : Adaptive Toolbar On Orientation Change

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:52 25 4
gpt4 key购买 nike

当我改变 iPad 的方向时,我的工具栏出现问题。

我将我的 nib 文件设置为横向,一切正常,但是当我将它设置为纵向时,我的工具栏仍然具有横向的宽度。

我如何使我的工具栏适应纵向更改的方向?

景观: enter image description here

肖像:

enter image description here

谢谢!

最佳答案

尝试将 UIViewAutoresizingFlexibleWidth 添加到工具栏 autoresizingMask,如下所示:

myToolbar.autoresizingMask |= UIViewAutoresizingFlexibleWidth

或者,如果您在 Interface Builder 中执行此操作,请确保选择了该水平条(也可以选择其他水平条,这很好):

enter image description here

更多来自 UIView Class Reference关于 autoresizingMask:

When a view’s bounds change, that view automatically resizes its subviews according to each subview’s autoresizing mask. You specify the value of this mask by combining the constants described in UIViewAutoresizing using the C bitwise OR operator. Combining these constants lets you specify which dimensions of the view should grow or shrink relative to the superview. The default value of this property is UIViewAutoresizingNone, which indicates that the view should not be resized at all.

When more than one option along the same axis is set, the default behavior is to distribute the size difference proportionally among the flexible portions. The larger the flexible portion, relative to the other flexible portions, the more it is likely to grow. For example, suppose this property includes the UIViewAutoresizingFlexibleWidth and UIViewAutoresizingFlexibleRightMargin constants but does not include the UIViewAutoresizingFlexibleLeftMargin constant, thus indicating that the width of the view’s left margin is fixed but that the view’s width and right margin may change. Thus, the view appears anchored to the left side of its superview while both the view width and the gap to the right of the view increase.

If the autoresizing behaviors do not offer the precise layout that you need for your views, you can use a custom container view and override its layoutSubviews method to position your subviews more precisely.

关于objective-c - Objective-C : Adaptive Toolbar On Orientation Change,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8161055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com