开发者

Obtain location coordinates from UIButton

开发者 https://www.devze.com 2023-04-10 11:28 出处:网络
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 locati

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

精彩评论

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

关注公众号