I have a UIView that displays a popup after it's been clicked. The popup needs to be added to the main UIWindow to make sure that it goes on top of everything else.
I want the position of this popup to be relative to my UIView, so I need to know the relative location of my UIView in the window.
Question: How can I find the location of a UIView in a UIWindow when the UIView is not directly in the UIWindow (It's inside the view of my viewController)?
Use can use the UIView method covertRect:toView to convert to the new co-ordinate space. I did something very similar:
// Convert the co-ordinates of the view into the window co-ordinate space
CGRect newFrame = [self convertRect:self.bounds toView:nil];
// Add this view to the main window
[self.window addSubview:self];
self.frame = newFrame;
In my example, self is a view that is being removed from its superView and added to the window over the top of where it was. The nil parameter in the toView: means use the window rather than a specific view.
Hope this helps,
Dave
You can ask your .superview
to convert your origin
for you for you
CGPoint originGlobal = [myView.superview convertPoint:myView.frame.origin
toView:nil];
Does UIView's convertPoint:toView: not work? So:
CGPoint windowPoint = [myView convertPoint:myView.bounds.origin toView:myWindow];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With