zoukankan      html  css  js  c++  java
  • iOS判断是否是手写键盘

    github:

    思路:遍历键盘window的subviews,如果发现UIKBHandwritingView,则当前键盘为手写键盘;

    手写键盘的位置:

    UIRemoteKeyboardWindow  

      UIInputSetContainerView

        UIInputSetHostView

          _UIKBCompatInputView

            UIKeyboardAutomatic

              UIKeyboardImpl

                UIKeyboardLayoutStar

                  UIKBKeyplaneView

                    UIKBHandwritingView

                    UIKBHandwritingCandidateView

     

     

    注意,上图显示UIKeyboardLayoutStar是UIKeyboardImpl的第一个view,但是iPad的实际如下图:

    // 思路:判断有没有UIKBHandwritingView,遍历所有view

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

    {

    #warning 担心苹果改变键盘结构,没有取到UIKBHandwritingView;造成无法消费!

     

        NSString *yuan = @"邓超界";

        if (![string isEqualToString:yuan]) {

            [SVProgressHUD showErrorWithStatus:@"签名不是持卡人姓名,请重写;如果不是手写键盘,请长按或者点击键盘上左下角的地球图标,选择 简体手写"];

            textField.text = @"";

            return NO;

        }

        if ([string isEqualToString:@" "]) {

            return NO;

        }

        // 判断有没有UIKBHandwritingView  遍历所有view

        UIView *handwritingView;

        for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {

            if ([[keyboardWindow description] hasPrefix:@"<UIRemoteKeyboardWindow"] == YES) {

                for (UIView *setContainer in keyboardWindow.subviews) {

                    if ([[setContainer description] hasPrefix:@"<UIInputSetContainerView"] == YES) {

                        for (UIView *setHost in setContainer.subviews) {

                            if ([[setHost description] hasPrefix:@"<UIInputSetHostView"] == YES) {

                                for (UIView *compat in setHost.subviews) {

                                    if ([[compat description] hasPrefix:@"<_UIKBCompatInputView"] == YES) {

                                        for (UIView *automatic in compat.subviews) {

                                            if ([[automatic description] hasPrefix:@"<UIKeyboardAutomatic"] == YES) {

                                                for (UIView *lmpl in automatic.subviews) {

                                                    if ([[lmpl description] hasPrefix:@"<UIKeyboardImpl"] == YES) {

                                                        for (UIView *layoutStar in lmpl.subviews) {

                                                            if ([[layoutStar description] hasPrefix:@"<UIKeyboardLayoutStar"] == YES) {

                                                                for (UIView *plane in layoutStar.subviews) {

                                                                    if ([[plane description] hasPrefix:@"<UIKBKeyplaneView"] == YES) {

                                                                        for (UIView *view in plane.subviews) {

                                                                            if([[view description] hasPrefix:@"<UIKBHandwritingView"] == YES){

                                                                                handwritingView = view;

                                                                                break;

                                                                            }

                                                                        }

                                                                        break;

                                                                    }

                                                                }

                                                                break;

                                                            }

                                                        }

                                                        break;

                                                    }

                                                }

                                                break;

                                            }

                                        }

                                        break;

                                    }

                                }

                                break;

                            }

                        }

                        break;

                    }

                }

                break;

            }

        }

     

        if (handwritingView) {

            // 截屏

            [self printscreenOfView:handwritingView];

            [SVProgressHUD showSuccessWithStatus:@"签名正确"];

        }else

        {

            [SVProgressHUD showInfoWithStatus:@"请长按或者点击键盘上左下角的地球图标,切换键盘为 简体手写"];

            textField.text = @"";

            return NO;

        }

        return YES;

    }

    for in,如果遍历的数组元素个数为零,不会执行遍历; 

    break终止循环执行循环体下面的代码
    return终止循环并且退出循环所在的方法
    continue终止当前循环,进行下一次循环

  • 相关阅读:
    深度学习:卷积神经网络(convolution neural network)
    Caffe使用step by step:r-cnn目标检测代码
    Caffe使用step by step:使用自己数据对已经训练好的模型进行finetuning
    Caffe使用step by step:caffe框架下的基本操作和分析
    (论文阅读)2015.10.8图像识别中的深度学习
    Caffe搭建:常见问题解决办法和ubuntu使用中遇到问题(持续更新)
    Ubuntu 14.04(64bit)使用indicator-sysmonitor显示系统运行状态
    SpringBoot配置文件自动映射到属性和实体类(8)
    SpringBoot热部署(7)
    SpringBoot之MultipartFile文件上传(6)
  • 原文地址:https://www.cnblogs.com/dengchaojie/p/6952206.html
Copyright © 2011-2022 走看看