【问题标题】:UITextView - How to remain cursor after hide keyboardUITextView - 隐藏键盘后如何保持光标
【发布时间】:2014-10-08 02:55:47
【问题描述】:

我正在尝试制作一个用户可以输入文本和表情符号的 UITextView。

我在显示光标时遇到了问题。

我的目标是让光标在选择表情时正常显示(键盘已隐藏)。

我知道它可以做到,因为一个名为“Kakao Story”的应用程序具有该功能。

有人有解决办法吗?谢谢。

【问题讨论】:

    标签: cursor uitextview


    【解决方案1】:

    我找到了一种隐藏键盘视图以访问我的目的的方法。

    这里是代码

    + (void)hideKeyboard
    {
        for (UIWindow *aWindow in [[UIApplication sharedApplication] windows]) {
    
            for (UIView *possibleKeyboard in [aWindow subviews]) {
                UIView *keyboardView = [self getPeripheralHostViewFromView:possibleKeyboard];
                if (keyboardView) {
                    [keyboardView setHidden:YES];
                }
            }
        }
    }
    
    + (void)unhideKeyboard
    {
        for (UIWindow *aWindow in [[UIApplication sharedApplication] windows]) {
    
            for (UIView *possibleKeyboard in [aWindow subviews]) {
                UIView *keyboardView = [self getPeripheralHostViewFromView:possibleKeyboard];
                if (keyboardView) {
                    [keyboardView setHidden:NO];
                }
            }
        }
    }
    
    + (UIView *)getPeripheralHostViewFromView:(UIView *)superView
    {
        if ([superView.description hasPrefix:@"<UIPeripheralHostView"]) {
            return superView;
        }else if([superView.description hasPrefix:@"<UIKBInputBackdropView"]) {
            return superView.superview;
        }else {
            for (UIView *subView in superView.subviews) {
                UIView *keyboardHostView = [self getPeripheralHostViewFromView:subView];
                if (keyboardHostView) {
                    return keyboardHostView;
                }
            }
        }
        return nil;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-24
      • 2012-07-16
      • 2014-12-13
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-16
      相关资源
      最近更新 更多