Get Position of UIView within entire UIWindow
The position of a UIView
can obviously be determined by view.center
or view.frame
etc. but this only returns the position of the UIView
in relation to it's immediate superview.
I need to determine the position of the UIView
in the entire 320x480 co-ordinate system. For example, if the UIView
is in a UITableViewCell
it's position within the window could change dramatically irregardless of the superview.
Any ideas if and how this is possible?
Cheers :)
That's an easy one:
[aView convertPoint:localPosition toView:nil];
... converts a point in local coordinate space to window coordinates. You can use this method to calculate a view's origin in window space like this:
[aView.superview convertPoint:aView.frame.origin toView:nil];
2014 Edit: Looking at the popularity of Matt__C's comment it seems reasonable to point out that the coordinates...
在Swift中:
let globalPoint = aView.superview?.convertPoint(aView.frame.origin, toView: nil)
Swift 4 :
let globalPoint = aView.superview?.convert(aView.frame.origin, to: nil)
链接地址: http://www.djcxy.com/p/39468.html
上一篇: iPhone,重现放大镜效果