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

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

问题描述

我想在窗口坐标系中获取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 的原点,而是参考了苹果文档 UIWindow 类 Reference 并使用此代码将键盘的 endCenter 转换为我的视图坐标系 [self.view convertPoint:endCentre fromView:[UIApplication sharedApplication].keyWindow].这段代码有效,因此解决了我的问题.然而,问题仍然存在,为什么它没有给出 scrollView.origin 的正确坐标.所以,基本上我通过转换键盘 endcenter 而不是 scrollView.origin 获得了解决方法.哦,我正在做所有这些事情,以便在键盘出现在屏幕上时计算我的滚动视图的新高度.因此,如果有人对此问题有解决方案或任何更好的解决方案,请告诉我们所有人.

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 原点转换为其窗口坐标系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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