如何获得正确的动画:UINavigationController 的导航栏中的 inputView?
我有一个自定义 UIControl 子类,其中 UIPickerView 作为 inputView。当点击控件时,它会调用 becomeFirstResponder
并且选择器视图会自动从屏幕底部向上滑动,就像系统键盘一样。这太棒了!
问题是我使用自定义控件作为 UINavigationItem 的 titleView。它可以正常工作,但是如果在选择器视图可见时视图控制器从导航控制器堆栈中弹出,则动画会不稳定。
我想要发生的事情:
- 所有内容都同时从屏幕向右推出
实际发生的情况:
- 首先,背景视图和导航栏滑出屏幕,选择器保持在原位
- ,然后,在它们消失后,选择器滑落 。
当我在视图控制器的主视图中使用自定义控件时,它也会像标准键盘一样动画消失 因此,这似乎是“来自”导航栏的功能,导航栏的动画与内部视图分开。
我该如何解决这个问题,以便 inputView 与其余内容一起滑出?
I have a custom UIControl subclass with a UIPickerView as inputView. When the control is tapped, it calls becomeFirstResponder
and the picker view automatically slides up from the bottom of the screen, like the system keyboard. This is working great!
The problem is that I am using the custom control as the titleView of a UINavigationItem. It functions properly, but if the view controller is popped off the navigation controller stack while the picker view is visible, the animation is wonky.
What I want to happen:
- everything is pushed off screen to the right at the same time
What actually happens:
- first, the background view and navigation bar slide off screen, the picker remains in place
- then, after they are gone, the picker slides off to the right also
When I use the custom control inside the view controller's main view, it animates away just like the standard keyboard. So it seems as though this is a function of "coming from" the navigation bar, which is animated separately from the views inside.
How can I fix this, so that the inputView slides out with the rest of the content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,这个问题可以通过在 UINavigationController 的视图上调用
endEditing:
来解决。换句话说,在视图控制器内:这会导致输入视图向下滑动,而视图的其余部分向右滑动。与系统键盘不完全相同,但也没有明显的奇怪。
Turns out this can be fixed by calling
endEditing:
on the UINavigationController's view. In other words, within a view controller:This causes the input view to slide down while the rest of the view slides off to the right. Not exactly the same as the system keyboard, but not obviously weird.