Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 获取按钮位置_Ios_Swift_Uicollectionview_Uibutton - Fatal编程技术网

Ios 获取按钮位置

Ios 获取按钮位置,ios,swift,uicollectionview,uibutton,Ios,Swift,Uicollectionview,Uibutton,我有一个tableview,在这个tableview的单元格中有一个collectionview。以及此collectionview单元格中的按钮。我需要这个按钮按下时的位置(它在屏幕上的位置)。我无法得到正确的值 使用转换器,每个UIView是一个UICoordinateSpace,UIScreen也有2个UICoordinateSpace对象(currentCoordinateSpace和fixedCoordinateSpace) 因此,最简单的方法是使用button.convert(bu

我有一个tableview,在这个tableview的单元格中有一个collectionview。以及此collectionview单元格中的按钮。我需要这个按钮按下时的位置(它在屏幕上的位置)。我无法得到正确的值

使用转换器,每个UIView是一个UICoordinateSpace,UIScreen也有2个UICoordinateSpace对象(
currentCoordinateSpace
fixedCoordinateSpace


因此,最简单的方法是使用
button.convert(button.bounds,to:UIScreen.main.coordinateSpace)
,这将把边界从
UIButton
坐标空间直接转换为
UIScreen
当前坐标空间。

使用转换器,每个
UIView
都是
UICoordinateSpace
。所以,最简单的方法是使用
按钮。convert(button.bounds,to:UIScreen.currentCoordinateSpace)
,这将把UIButton坐标空间中的bounds rect转换为UIScreen当前坐标空间中的Swift 4:button。convert(button.bounds,to:UIScreen.main.coordinateSpace)解决了我的问题。谢谢!