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