2011-09-30 19 views
0

mainviewcontrollerのサブビューにあるUIButtonの座標を取得しようとしています。下のコードでサブビューを基準にして返すことができますが、mainviewcontrollerに関連してUIButtonの位置を返すにはどうすればよいですか?UIButtonから位置座標を取得

ScrollingAppDelegate * appDelegate =(ScrollingAppDelegate *)[[UIApplication sharedApplication] delegate]; CGPoint canXY = appDelegate.globalcanButtonReference.frame.origin; NSLog(@ "%f%f"、canXY.x、canXY.y);あなたは、これは動作するはずです、すべてのビューへの参照を持っていないと仮定すると、

答えて

1

CGPoint buttonOrigin = appDelegate.globalcanButtonReference.frame.origin; 
CGPoint superViewOrigin = appDelegate.globalcanButtonReference.superview.frame.origin; 
CGPoint pointInMainViewController = CGPointMake(buttonOrigin.x + superViewOrigin.x, buttonOrigin.y + superViewOrigin.y); 
+0

これは素晴らしい仕事、ありがとう、私は本当に感謝束:) – user973984

関連する問題