MonoTouch:ResignFirstResponder() 问题

发布于 2024-12-22 18:50:49 字数 1076 浏览 0 评论 0原文

我有一个 UIScrollView 存储多个 UIView。当我的键盘弹出时,我使用 UIKeyboardDidShowNotification 调整此 UIScrollView 的大小,以便我的可视内容区域仅位于键盘上方。我这样做是这样的:

contentArea.Frame = new System.Drawing.RectangleF(0, contentArea.Frame.Top, 1024, 768 - contentArea.Frame.Top - r.Height);      

现在,当键盘正常消失并且 UIKeyboardWillHideNotification 触发时,我可以使用以下命令轻松重置它,并且效果很好:

contentArea.Frame = new System.Drawing.RectangleF(0, contentArea.Frame.Top, 1024, 627); 

我的问题是当我必须切换视图时,我需要隐藏这个键盘。为此,我在 UITextField 上调用 ResignFirstResponder()

  • 如果我从未在 UITextField 中输入任何文本,则效果很好。
  • 如果我根本不滚动视图,则一切正常。
  • 但是,如果输入文本并且发生滚动,我的 UIScrollView 将返回到其原始大小,但它现在具有滚动距离的偏移量 * -1。因此,如果偏移量是 50,那么现在是 -50。这意味着我的视图顶部距离 UIScrollView 向下 50 像素。

如果我手动更新 UIScrollView 的偏移量,它不会执行任何操作。要真正解决此问题,我必须在新的 UITextField 内部单击,它将将此 UIScrollView 中的所有视图修复为应有的样子。

非常感谢任何有关如何解决此问题的帮助!我正在从 5.0 更新到 5.1,希望这是一个可以修复的错误,但我的希望很低。

I have a UIScrollView that stores a several UIViews. I am using UIKeyboardDidShowNotification to resize this UIScrollView when my keyboard pops up so that my viewable content area is only what is above the keyboard. I do so with:

contentArea.Frame = new System.Drawing.RectangleF(0, contentArea.Frame.Top, 1024, 768 - contentArea.Frame.Top - r.Height);      

Now when the keyboard disappears normally and UIKeyboardWillHideNotification fires, I can easily reset this with with following, and it works great:

contentArea.Frame = new System.Drawing.RectangleF(0, contentArea.Frame.Top, 1024, 627); 

My issue is when I have to switch views, I need to hide this keyboard. To do so I am calling ResignFirstResponder() on my UITextField.

  • If I never enter any text into the UITextField, this works fine.
  • If I do not scroll my view at all this works fine.
  • However, if text was entered and there was scrolling, my UIScrollView returns to it's original size, but it now has an offset of how far it was scrolled * -1. So if the offset was 50, it now is -50. This means the top of my view is 50 pixels down the UIScrollView.

If I manually update the offset of the UIScrollView, it does not do anything. To actually fix this, I have to click inside a new UITextField and it fixes all my views in this UIScrollView to what it should be.

Any help on how to fix this is much appreciated! I am updating from 5.0 to 5.1 hoping this is a bug that hopefully was fixed, but my hopes are low.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野生奥特曼 2024-12-29 18:50:49

这不是您问题的解决方案,但可能是实现功能的另一种方式:
您无需调整大小,只需滚动到该位置(因为您使用的是 UIScrollView)。
可以找到一个示例 这里。在示例中,您将覆盖 KeyboardGetActiveView 并返回应该可见的视图。

It is not a solution to your problem but maybe an other way to archieve the functionality:
Instead of resizing you just scoll to the position (since you are using the UIScrollView).
An example can be found here. In the example you would overwrite KeyboardGetActiveView and return the View that should be visible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文