点击外部选择器文本不打开选择器菜单
我有一个picker
这样的
Picker ("", selection: $itemIndex){
ForEach (0..<items.count, id: \.self){ index in
Text(items[index])
}
}
.frame(maxWidth: .infinity)
.background(.red)
问题是,选择器延伸到屏幕宽度,但是
在我单击时, 挑选器上显示的文本并不冗长,也许大约是Picker长度的1/20文本,选择器菜单会打开,但是当我单击文本外部,仍在选择器可见性中时,菜单不会打开。
在上图中,当我点击红色侧时,菜单会打开,但是当我点击两个绿色的侧面时,没有
人知道为什么会发生这种情况?
注意:选择器不在表单
或navigation controller
中
I have a Picker
like this
Picker ("", selection: $itemIndex){
ForEach (0..<items.count, id: \.self){ index in
Text(items[index])
}
}
.frame(maxWidth: .infinity)
.background(.red)
The issue is that the picker extends to the screen width but the text displaying on the Picker is not that lengthy, maybe about 1/20 of the Picker length
Now when I click on the text, the Picker menu opens up, but when I click outside the text, still within the picker visibility, the menu don't open.
In the image above, when I tap on the red side, the menu opens up, but when I tap on both green sides it doesn't
Do anyone have an idea why this is happening?
Note: the picker is not in a Form
or a NavigationController
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的...因此,在这个问题,我能够自定义自己的
picker
样式。以下是实现此目的的代码,这就是我在UI中使用它的方式
,这是结果
< img src =“ https://i.sstatic.net/7ittv.png” alt =“在此处输入图像说明”>
Okay... So through the help of this question, I was able to customize my own
Picker
style. Below is the code to achieve thisAnd I this is how I used it in my UI
And here is the result
我假设您想要这个
或这样做,如果您告诉有关
菜单
一般规则是 - 为标签提供空间,而该标签的空间实际上显示而不是包含控件,因为通常由固有内容设置hit Testing。
I assume you wanted this
or this if you told about
Menu
the general rule is - give space for label which is actually shown, instead of containing control, because hit testing is usually set up by intrinsic content.