我陷入了Objective C ViewController基础应用程序
中的Local to Global Point问题我有一个ScrollView作为ViewController的SubView,它有大约13到15个UIButton作为SubView,一次只有3个UIButton位于ScrollView的视图中。
我想要的是获取UIButton的CGPoint(全局),它是ScrollView的子视图,但不是ScrollView中的本地CGpoint。
有没有办法让Local CGPoint转换为Global CGPoint。
谢谢Guyz KK
答案 0 :(得分:3)
说你有UIButton myButton
,请尝试:
CGPoint globalPoint = [[[UIApplication sharedApplication] keyWindow] convertPoint:CGPointZero fromView:myButton]
;
并转换回来
CGPoint localPoint = [myButton convertPoint:globalPoint fromView:[[UIApplication sharedApplication] keyWindow]]
;
答案 1 :(得分:0)
但是,不要只添加包含对象的坐标吗?事实上,如果你有一个位于
的视图x: 10 y: 10: w: 100 h: 100
,另一个有视图
x: 10 y: 10 w: 20 h: 20
第二个中心是:(20,20),而x和y的总和得到全球中心,即(30.30)