我正在尝试获取主视图控件的子视图中的UIButton的坐标。我可以使用下面的代码将它们相对于子视图返回,但是如何返回与mainviewcontroller相关的UIButton位置?
ScrollingAppDelegate * appDelegate =(ScrollingAppDelegate *)[[UIApplication sharedApplication] delegate]; CGPoint canXY = appDelegate.globalcanButtonReference.frame.origin; NSLog(@“%f%f”,canXY.x,canXY.y);
答案 0 :(得分: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);