I am creating a app and need to get the button’s frame respect to the view.
I have a mapview with annotation. While selecting the annotation it shows a callout bubble. That has a button as right accessary view. I have a selector that gets invoked when I tap on that button.
Now I want to get the frame of the button with respect to the view’s bound. I want to know where the button is located in the view?
For that I tried:
[self.view convertRect:btn.frame fromView:self.view];
and
[self.view convertRect:btn.frame toView:self.view];
I am not getting correct result.
The
btn.frameis relative to its (the button’s) super view so passingself.viewforfromViewwon’t give the expected result becauseself.viewis not the button’s super view (in the case of an annotation callout button). So that code should be:Similarly in the
toViewcall, the method needs to be called on the button’s super view sincebtn.frameis relative to it (notself.view):