UIKeyboard 关闭后在 UIPopoverController 内显示 UIDatePicker

发布于 2024-11-14 02:22:33 字数 614 浏览 5 评论 0原文

我正在用这个拔掉我的头发。

我在弹出窗口中有一个表格,允许用户编辑一些数据。大多数可编辑单元格都需要用户通过键盘输入数据,但需要一个 UIDatePicker。当 UIDatePicker 呈现给用户时,它通过抓取视图的大小并执行动画从弹出窗口的底部滑入。但是,如果这种情况发生在键盘关闭之后,则在弹出窗口重置回其原始位置之前会抓取视图的大小(即,当弹出窗口在被“挤压”到屏幕顶部后调整回正常大小时)这使得 UIDatePicker 位于弹出窗口的中间,

我尝试添加延迟,并使用 UIKeyboardWillHideNotification,但我无法让它工作,

然后再获取视图的大小并执行。动画?

更新 1

我自己解决了这个问题,但我会在这里发布答案,以防其他人需要它。然后,我不再每次想要对 UIDatePicker 进行动画处理时抓取视图的边界,而是简单地使用 CGRect 变量。

上述修复在大多数情况下有效,但不起作用 对于所有人来说,我现在遇到的问题是在键盘完全关闭之前显示新的弹出窗口(即动画输出的一半)。这给出了当前大小的界限,然后将其调整为所需的实际大小。此外,一旦键盘关闭,弹出窗口似乎不会调整回其原始大小。

大家有什么想法吗?

I am pulling my hair out with this one.

I have a table inside a popover which allows the user to edit some data. Most of these editable cells need the user to enter data via the keyboard, but one needs a UIDatePicker. When the UIDatePicker is presented to the user, it slides in from the bottom of the popover by grabbing the size of the view and performing an animation. However, if this happens after the keyboard is dismissed then the size of the view is grabbed before the popover is reset back its original position (i.e. when the popover is resizing back to normal size after being 'squashed" toward the top the the screen). This leaves the UIDatePicker halfway up the popover.

I have tried adding a delay, and using an UIKeyboardWillHideNotification, but I cannot get this to work.

How can I wait for the popover to finish resizing before I grab the size of the view and perform the animation?

Update 1

I managed to work this out myself, but I'll post the answer here just incase anyone else needs it. Basically I set up a CGRect variable which gets populated with the views bounds when the view loads. Then instead of grabbing the bounds of the view each time I want to animate the UIDatePicker in, I simply use the CGRect variable instead.

Update 2

The above fix works in most cases, but not for all. The problem I am now having is when a new popover is displayed before the keyboard is fully dismissed (i.e. half way down it's animation out). This gives bounds at it's current size, before it is then resized to the actual size it needs to be. Also, the popover doesn't seem to resize back to its original size once the keyboard is dismissed.

Any ideas folks?

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

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

发布评论

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

评论(1

善良天后 2024-11-21 02:22:33

解决了。

当键盘在弹出窗口委托中关闭时,我检查弹出窗口是否正在显示,然后将其重新定位到其原始大小和位置。如果有人感兴趣的话我有代码。就评论我吧。

Solved.

When keyboard is dismissed in the popover delegate, I check that the popover is being displayed and then reposition it to its original size and location. I have the code if anyone is interested. Just comment me up.

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