将UIView原点转换为其Window坐标系 [英] Convert a UIView origin point to its Window coordinate system

查看:168
本文介绍了将UIView原点转换为其Window坐标系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在窗口坐标系中获取scrollView的原点。例如,目前,scollView的起源是(0,51)。但是在窗口坐标系中它应该是51 + 44(导航栏高度)+20(状态栏高度)= 115.在窗口坐标系中,scrollView.frame.origin应该是(0,115)。我尝试使用convertPoint:方法但有时得到(0,51)或(0,0)。请提供解决方案。谢谢

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 + 44(navigation bar height)+20(status bar height) = 115. Means in window coordinate system the scrollView.frame.origin should be (0,115). I tried with convertPoint: methods but getting (0,51) or (0,0) sometimes. Please provide a solution to this. Thanks

推荐答案

我尝试使用TechZen解决方案,但无济于事。我没有转换scrollView的原点,而是提到了apple docs UIWindow类Reference,并使用这段代码 [self.view convertPoint:endCentre fromView:[UIApplication sharedApplication]将键盘的endCenter转换为我的视图坐标系。 keyWindow] 。这段代码工作,因此解决了我的问题。 然而,问题仍然是为什么它没有给出scrollView.origin.So的正确坐标,基本上我通过转换键盘endcenter而不是scrollView.origin 得到了一个解决方法。哦,我正在做所有这些事情,以便在键盘出现在屏幕上时计算我的scrollView的新高度。所以,如果有人能解决这个问题或任何更好的解决方案,请让我们所有人都知道。

I tried with TechZen solution but to no avail. Instead of converting scrollView's origin,I referred to apple docs UIWindow class Reference and converted the endCenter of the keyboard to my view's coordinate system by using this code [self.view convertPoint:endCentre fromView:[UIApplication sharedApplication].keyWindow]. This piece of code worked and hence solved my problem. However, the question still remains as to why it does not gives the proper coordinate of scrollView.origin.So, basically I got a workaround by converting keyboard endcenter instead of scrollView.origin. Oh, and I was doing all this stuff in order to calculate my scrollView's new height when keyboard appears on screen. So, if somebody has a solution to this problem or any better solution, Please let all of us know.

这篇关于将UIView原点转换为其Window坐标系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆