如何确定在 SwiftUI 中弹出框是否显示为弹出框或工作表?
在 SwiftUI 中,当显示弹出框时,它将显示为弹出框或工作表,具体取决于设备(iPad 或 iPhone)和可用的窗口空间。
是否有正确的启发式方法来检查弹出窗口是否显示为弹出窗口或工作表?
例如,在 iPad 上,当多任务处理且垂直或水平且四分之一屏幕大小时,弹出框将显示为工作表。
In SwiftUI when a popover is displayed, it will display as either a popover or sheet depending on the device (iPad or iPhone) and window space available.
Is there a correct heuristic to check if the popover will be displayed as a popover or a sheet?
For example, on iPad, a popover will show as a sheet when multitasking and vertical or when horizontal at quarter-screen size.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的答案是我需要从呈现弹出窗口的父视图传递
horizontalSizeClass
。.environment(\.horizontalSizeClass, HorizontalSizeClass)
如果没有这个,子视图将读取可用的horizontalSizeClass
(它在弹出窗口中始终是紧凑的)。The answer here is that I needed to pass down
horizontalSizeClass
from the parent view that was presenting the popover..environment(\.horizontalSizeClass, horizontalSizeClass)
Without this, the child view was reading thehorizontalSizeClass
that was available to it (which is always compact within a popover).根据我的测试,您可以使用
@Environment(\.horizontalSizeClass)
来查找:Based on my testing you CAN use
@Environment(\.horizontalSizeClass)
to find out: