gpt4 book ai didi

Swift获取当前元素的Y坐标

转载 作者:行者123 更新时间:2023-11-28 07:06:04 25 4
gpt4 key购买 nike

我得到了一些 UILabel,按下它可以打开菜单。按下时,他们以标签本身作为参数调用我的函数。我制作了一个在手机 View 中表现正确的弹出窗口,但我想在它在 ipad View 中定位它。

我的问题是我无法获得按下的 UILabel 的确切位置。

我试过了

myYCoordinates = label.bounds.origin.y

myYCoordinates = label.frame.origin.y

optionMenu.popoverPresentationController?.sourceRect = CGRectMake(self.view.bounds.size.width / 2, myYCoordinates, 1.0, 1.0)

但是我找不到好的坐标。

我不知道是不是因为我的标签在一个有 2 个部分的 tableview 中,或者是否有办法。

预先感谢您的帮助。


这是我的场景(由于开发 secret 而被裁剪) enter image description here这是我按下标签时附加的内容 enter image description here这就是我想要的样子 enter image description here


我试过了optionMenu.popoverPresentationController?.sourceRect = label.frame

enter image description here

最佳答案

根据@Özgür Erzil 的回答,我发现我可以简单地使用

optionMenu.popoverPresentationController?.sourceView = label
optionMenu.popoverPresentationController?.sourceRect = CGRectMake(label.frame.width, label.frame.height / 2, 1.0, 1.0)

通过将源 View 设置为我的标签并使用标签宽度和高度来定位它。

感谢

关于Swift获取当前元素的Y坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30601040/

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