iosobjective-cuiviewcgrect

UIView absolute screen point


Is there an easy way of getting the absolute point of UIView? By absolute I mean the location of the UIView relative to 1024x768 on an iPad?

I need an easy way because I have a UIButton inside a UITableViewCell inside a UITableView inside a view presented by a viewcontroller that is a child of another view controller repeating to the fifth or sixth view controller. And due to this complex design I need the absolute rect of the UIButton so I can display an UIActionSheet on the "main" viewcontroller.


Solution

  • So I ended up using UITapGestureRecognizer instead and calculating the position like this:

        CGPoint gestureViewLocation = [gesture locationInView:gesture.view];
        CGPoint absoluteLocation = [gesture locationInView:self.parentViewController.view];
        CGRect fromRect = CGRectMake(absoluteLocation.x-gestureViewLocation.x, //subtract to we get point relative to gesture view
                                     absoluteLocation.y-gestureViewLocation.y, //subtract to we get point relative to gesture view
                                     gesture.view.frame.size.width,
                                     gesture.view.frame.size.height);