将 UIKeyboardFrameEndUserInfoKey 转换为视图或窗口坐标 [英] Convert UIKeyboardFrameEndUserInfoKey to View or Window Coordinates

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

问题描述

对于常量 UIKeyboardFrameEndUserInfoKey,在 Apple 文档中它说:

For the constant UIKeyboardFrameEndUserInfoKey, in the Apple docs it says:

这些坐标没有考虑任何旋转因素由于界面方向而应用于窗口的内容变化.因此,您可能需要将矩形转换为窗口坐标(使用 convertRect:fromWindow: 方法)或查看使用前坐标(使用 convertRect:fromView: 方法).

These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.

所以如果我使用 [view1 convertRect:rect fromView:view2]

我会为上述参数插入什么以使其正确转换旋转值?即:

What would I insert for the above parameters to get it to convert the rotation values correctly? ie:

视图 1 = ?正确 = ?(我假设的键盘框架)视图 2 = ?

view1 = ? rect = ? (the keyboard frame I'm assuming) view2 = ?

一直在尝试一些东西并得到一些有趣的东西.

Been trying some things and getting some funny stuff.

推荐答案

第一个视图应该是您的视图.第二个视图应该为零,表示窗口/屏幕坐标.因此:

The first view should be your view. The second view should be nil, meaning window/screen coordinates. Thus:

NSDictionary* d = [notification userInfo];
CGRect r = [d[UIKeyboardFrameEndUserInfoKey] CGRectValue];
r = [myView convertRect:r fromView:nil];

现在就您的视图而言,您拥有了键盘将占据的矩形.如果您的视图是当前视图控制器的视图(或其子视图),则现在考虑旋转等.

Now you have the rect that the keyboard will occupy, in terms of your view. If your view is the current view controller's view (or a subview thereof), rotation and so forth are now accounted for.

这篇关于将 UIKeyboardFrameEndUserInfoKey 转换为视图或窗口坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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