gpt4 book ai didi

objective-c - 更改 UI 元素/对象的 XY 位置

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:08 24 4
gpt4 key购买 nike

我想知道为什么您无法在 objective-c 中更改某些对象的 XY 位置?例如...我有一个包含以下代码的工具栏,但只有当我将它放在 UIView 中然后设置相同的坐标时它才有效...任何人都可以解释为什么吗?

不起作用:

 UIToolbar *commentstoolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 400, 320, 44)];
[self.view addSubview:commentstoolbar];

有效:

 UIToolbar *commentstoolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIView *toolbarView = [[UIView alloc] initWithFrame:CGRectMake(0, 400, 320, 44)];

[toolbarView addSubview:commentstoolbar];
[self.view addSubview:toolbarView];

最佳答案

UIToolbar 符合 UIBarPositioning协议(protocol),它指定:

The UIBarPositioning protocol defines the ways that bars can be positioned on iOS devices. Bars can be positioned at the bottom of their enclosing view, at the top of their enclosing view, or at both the top of their enclosing view and also the top of the screen.

因此解决在任何地方放置工具栏的方法是将它包含在 View 中,就像您正在做的那样。

关于objective-c - 更改 UI 元素/对象的 XY 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20470859/

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