开发者

CGPoint relative to view

开发者 https://www.devze.com 2023-01-28 03:04 出处:网络
Consider a 开发者_开发问答screen point (CGPoint) and a view (UIView), which is somewhere inside the view hierarchy (it can be a subview of other views).

Consider a 开发者_开发问答screen point (CGPoint) and a view (UIView), which is somewhere inside the view hierarchy (it can be a subview of other views).

How can you convert the point to a point relative to the view's coordinates?


First, convert the point from screen coordinates to the coordinates of your main window:

UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
CGPoint pointInWindowCoords = [mainWindow convertPoint:pointInScreenCoords fromWindow:nil];

Second, convert the point from window coords to view coords:

CGPoint pointInViewCoords = [myView convertPoint:pointInWindowCoords fromView:mainWindow];
0

精彩评论

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

关注公众号