iPhone correct landscape window coordinates

前端 未结 5 1060
终归单人心
终归单人心 2021-02-15 15:31

I am trying to get the window coordinates of a table view using the following code:

[self.tableView.superview convertRect:self.tableView.frame toView:nil]

5条回答
  •  情歌与酒
    2021-02-15 16:08

    Your code should be:

    [tableView convertRect:tableView.bounds toView:[UIApplication sharedApplication].keyWindow];
    

    That will give you the view's rectangle in the window's coordinate system. Be sure to use "bounds" and not "frame". frame is the rectangle of the view in its parent view coordinate system already. "bounds" is the view rectangle in its own system. So the above code asks the table view to convert its own rectangle from its own system to the window's system. Your previous code was asking the table's parent view to convert the table's rectangle from the parent coordinate system to nothing.

提交回复
热议问题