I create programmatically one scrollView and some buttons inside there. When I click the any button have to show a popover.
My button's origin in self.view is like (100,11) and inside scrollView (9,11) and scrowView is in somewhere in self.view. The popover shows in (9,11) but right one would be (100,11). I try use convert without success.
-(IBAction)showPopover:(id)sender{
//... implemented popover above
//Wrong Origin:
NSLog(@"wrong x:%f y:%f",[sender frame].origin.x, [sender frame].origin.y);
//Transform to correct
CGRect frame = [self.view convertRect:[sender frame] toView:nil];
//Shoulf be right, but is not...
NSLog(@"new x:%f y:%f",frame.origin.x, frame.origin.y);
}
Anyone cam help me?
A view's frame is already in the superview's coordinate system. So if your setup is self.view
contains scrollview
contains sender
:
CGRect frame = [sender.superview convertRect:sender.frame toView:self.view];
// or, better:
CGRect frame = [sender convertRect:sender.bounds toView:self.view];
Swift:
let frame = sender.convert(sender.bounds, to: self.view)
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