Convert a UIView origin point to its Window coordinate system

前端 未结 4 952
野的像风
野的像风 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条回答
  •  难免孤独
    2020-12-14 06:57

    Swift:

    In viewDidAppear(otherwise elements are not yet layered) of your ViewController:

            var yourFrame = yourScrollView.convertRect(yourScrollView.frame, to: self.view)
    
            //PRINT THE WHOLE RECT
            print(yourFrame)
    
            //PRINT A DETAILED VERSION OF THE FRAME, ALSO CAN PERFORM CALCULATION BETWEEN THE RECT PARAMETERS TO GET , FOR EXAMPLE, WIDTH POINT IN THE SUPERVIEW:
            print("X: \(yourFrame.origin.x) Y: \(yourFrame.origin.y) WIDTH: \(yourFrame.width) HEIGHT: \(yourFrame.height)")
    

提交回复
热议问题