【问题标题】:Getting UIButton postition获取 UIButton 位置
【发布时间】:2019-03-12 12:50:51
【问题描述】:

我有一个表格视图,并且在这个表格视图的一个单元格中有一个集合视图。和这个collectionview的一个单元格中的一个按钮。我需要按下此按钮的位置(它在屏幕中的位置)。我无法获得正确的值。

【问题讨论】:

  • 使用转换器,每个UIView是一个UICoordinateSpacedeveloper.apple.com/documentation/uikit/uicoordinatespace。因此,最简单的方法是使用button.convert(button.bounds, to: UIScreen.currentCoordinateSpace),这会将边界矩形从 UIButton 坐标空间转换为 UIScreen 当前坐标空间
  • 对于 Swift 4: button.convert(button.bounds, to: UIScreen.main.coordinateSpace) 解决了我的问题。非常感谢!

标签: ios swift uicollectionview uibutton


【解决方案1】:

使用转换器,每个 UIView 是一个 UICoordinateSpace,同时 UIScreen 有 2 个 UICoordinateSpace 对象(currentCoordinateSpacefixedCoordinateSpace)。

https://developer.apple.com/documentation/uikit/uicoordinatespace.

所以,最简单的方法是使用button.convert(button.bounds, to: UIScreen.main.coordinateSpace),这会将边界矩形从UIButton坐标空间转换为UIScreen当前坐标空间。

【讨论】:

    猜你喜欢
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 2011-08-03
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    相关资源
    最近更新 更多