Search code examples
iosswiftcoordinate

Get coordinates of button in UIWindow coordinate's


I have UITableView with some cells, inside those cells, I have a buttons. When I tap on the buttons, I need the coordinates of center button within UIWindow. How to do this?


Solution

  • From the UIView - convertRect:fromView: documentation

    view : The view with rect in its coordinate system. If view is nil, this method instead converts from window base coordinates.

    Try this line :

    CGRect buttonFrame = [sender.superview convertRect:sender.frame fromView:nil];
    

    This should get you the absolute button position.