大佬教程收集整理的这篇文章主要介绍了SwiftUI 在调用 contextMenu 修饰符时奇怪地移动某些视图的位置,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我遇到了一个问题,当我使用 .contextMenu(menuItems:) 修饰符时,某些 SwiftUI 视图(在某些配置下)将它们的位置移动到屏幕的中心,我不知道为什么。我在以下代码示例中以简化的方式重新创建了该问题:
struct ContentVIEw: VIEw {
var body: some VIEw {
Path { path in
path.move(to: CGPoint(x: 200,y: 100))
path.addline(to: CGPoint(x: 100,y: 300))
path.addline(to: CGPoint(x: 300,y: 300))
path.addline(to: CGPoint(x: 200,y: 100))
}
.contextMenu {
Text("hello world")
}
}
}
GIF that demonstrates how the triangle shifts to center screen for some reason due to the context menu invocation
struct ContentVIEw: VIEw {
var body: some VIEw {
Circle()
.position(x: 0,y: 0)
.frame(wIDth: 50,height: 50,alignment: .bottom)
.contextMenu {
Text("hello world")
}
}
}
GIF that demonstrates how the circle shifts to center screen and somehow gains a sharp edge due to the context menu invocation
如果有人知道这里发生了什么,我将不胜感激。我使用的是 Xcode 12.5.1、macOS 11.4 和 iOS 14.5。
通过添加特定的框架来塑造你可以解决这个问题,但我没有任何解释。
ok: [localhost] => (item=ccf_demo) =>
msg: |-
name: ccf_demo_segment1_group1 is group1:untagged
name: ccf_demo_segment1_group2 is group2:untagged
ok: [localhost] => (item=ccf_demo2) =>
msg: |-
name: ccf_demo2_t2seg1_othergroup is othergroup:untagged
skipping: [localhost] => (item=ccf_demo3)
以上是大佬教程为你收集整理的SwiftUI 在调用 contextMenu 修饰符时奇怪地移动某些视图的位置全部内容,希望文章能够帮你解决SwiftUI 在调用 contextMenu 修饰符时奇怪地移动某些视图的位置所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。