How to get the frame of a view inside another view?

后端 未结 4 2030
攒了一身酷
攒了一身酷 2020-12-04 16:38

I have an UIImageView in the self.view (the main View) and inside it there is a UIButton. I want to know what\'s the frame of UI

4条回答
  •  萌比男神i
    2020-12-04 17:20

    There are four UIView methods which can help you, converting CGPoints and CGRects from one UIView coordinate reference to another:

    – convertPoint:toView:
    – convertPoint:fromView:
    – convertRect:toView:
    – convertRect:fromView:
    

    so you can try

    CGRect f = [imageView convertRect:button.frame toView:self.view];
    

    or

    CGRect f = [self.view convertRect:button.frame fromView:imageView];
    

提交回复
热议问题