开发者

Obtain location coordinates from UIButton

I'm trying to obtain the coordinates of a UIButton that is in a subview of the mainviewcontroller. I can return them relative to the subview with the code below but how do I return the UIButton location as it relates to the mainviewcontroller?

ScrollingAppDelegate *appDelegate = (ScrollingAppDelegate *)[[UIApplicat开发者_StackOverflowion sharedApplication] delegate]; CGPoint canXY = appDelegate.globalcanButtonReference.frame.origin; NSLog(@"%f %f",canXY.x,canXY.y);


Assuming you don't have a reference to all of the views, this should work:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜