【问题标题】:Get position of embedded UIElement in screen coordinates in Swift在 Swift 中获取嵌入式 UIElement 在屏幕坐标中的位置
【发布时间】:2021-03-03 02:58:32
【问题描述】:

在 StoryBoard 中,我有一个嵌入在垂直 UIStackView 中的 UIprogressView,它本身嵌入在水平 UIStack 视图中。最后,最后一个 Horizo​​ntal UIStackView 嵌入到一个垂直 UIStack 视图中。我找到了访问 UIprogressView 的路径:

self.view.subviews[0].subviews[0].subviews[1].subviews[0]

在多次尝试使用 .convert 方法后,我绝对无法在屏幕坐标中找到我的 UIProgressView 的位置。我总是获得看起来与超级视图相关的坐标,但从不对应于它在屏幕上的明显位置。 我错过了什么?谢谢。

【问题讨论】:

    标签: swift position coordinates screen


    【解决方案1】:

    请发布您尝试转换它的方式。尝试应用我的示例,看看它是否适合您。

    为你的progressView创建一个出口,然后尝试将其框架转换为你需要的视图中的相应框架(在我的例子中是topMostView)。

    let progressViewGlobalFrame = progressView.convert(progressView.convert.frame, to: topMostView)
    

    【讨论】:

    • 我会看到的。谢谢!
    猜你喜欢
    • 2017-01-21
    • 2020-04-13
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 2015-10-26
    • 2016-10-09
    相关资源
    最近更新 更多