moving a bar with UIScrollViewKeyboardDismissModeInteractive(使用 UIScrollViewKeyboardDismissModeInteractive 移动条形图)
问题描述
我有一个固定在键盘顶部的文本字段.我不能使用 inputAccessoryView 因为它总是显示.我能够观察到键盘隐藏/显示通知以使用键盘上下移动,但这似乎不适用于 UIScrollViewKeyboardDismissModeInteractive.有没有办法获得关于键盘位置的持续反馈以同步动画?
I have a text field that I anchor to the top of the keyboard. I can't use inputAccessoryView since it's always shown. I'm able to observe keyboard hidden/shown notifications to move it up and down with the keyboard, but this doesn't appear to work with UIScrollViewKeyboardDismissModeInteractive. Is there a way to get constant feedback on the position of the keyboard to sync the animation?
推荐答案
看起来这在 iOS 8 中不起作用,伙计们——抱歉!我也在寻找新的解决方案
我通过创建一个不可见的 inputAccessoryView 解决了这个问题.
I solved this by creating a non-visible inputAccessoryView.
textView.inputAccessoryView = [[MJXObservingInputAccessoryView alloc] init];
accessoryView 观察其父视图的框架并发布一个您可以匹配的通知.
The accessoryView observes its superview's frame and posts out a notification you can match.
static NSString * const MJXObservingInputAccessoryViewSuperviewFrameDidChangeNotification = @"MJXObservingInputAccessoryViewSuperviewFrameDidChangeNotification";
@interface MJXObservingInputAccessoryView : UIView @end
@implementation MJXObservingInputAccessoryView
- (void)willMoveToSuperview:(UIView *)newSuperview
{
if (self.superview)
{
[self.superview removeObserver:self
forKeyPath:@"frame"];
}
[newSuperview addObserver:self
forKeyPath:@"frame"
options:0
context:NULL];
[super willMoveToSuperview:newSuperview];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if (object == self.superview && [keyPath isEqualToString:@"frame"])
{
[[NSNotificationCenter defaultCenter] postNotificationName:MJXObservingInputAccessoryViewSuperviewFrameDidChangeNotification
object:self];
}
}
@end
这篇关于使用 UIScrollViewKeyboardDismissModeInteractive 移动条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 UIScrollViewKeyboardDismissModeInteractive 移动条形图
基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01