2011-09-30 209 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