Convert a UIView origin point to its Window coordinate system

前端 未结 4 944
野的像风
野的像风 2020-12-14 06:20

I want to get the origin of scrollView in the window coordinate system. For Example, presently, scollView origin is (0,51). But in window coordinate system it should be 51 +

4条回答
  •  萌比男神i
    2020-12-14 07:08

    Note that these functions will only work after view controller finished laying out subviews. So if you want that when view loads, you can use viewDidLayoutSubviews / viewDidAppear, but not in viewDidLoad / viewWillAppear etc...

    This code worked for me:

    - (void)viewDidLayoutSubviews
    {
        [super viewDidLayoutSubviews];
    
        CGPoint originInSuperview = [self.view.superview convertPoint:CGPointZero fromView:self.scrollView];
    }
    

提交回复
热议问题