Convert a UIView origin point to its Window coordinate system

前端 未结 4 950
野的像风
野的像风 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 07:04

    It sounds like your not converting between the proper views. A view's frame is set to the coordinates of it's superview, not its own internal coordinates, so if you were trying to convert the origin of a view to window coordinates, you would need to use the superview:

    [[self superview] convertPoint:self.frame.origin toView:theWindow];
    

    However, it is even simpler to convert the zero point from the view itself to the window. The two pieces of code are equivalent, and so it isn't necessary to use the origin at all.

    [self convertPoint:CGPointZero toView:theWindow];
    

提交回复
热议问题