使用 UIScrollViewKeyboardDismissModeInteractive 移动条形图 [英] moving a bar with UIScrollViewKeyboardDismissModeInteractive

查看:13
本文介绍了使用 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 移动条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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