zoukankan      html  css  js  c++  java
  • webView 下的UIKeyBoard的 inputAccessView处理

    在输入的键盘上方加上一个view,作为一个toolBar,算是现在的基本需求,苹果自身有一个inputAccessoryView,是用来给这个view的,继承自NSObject (readonly),iputView与inputAccessoryView 在textView和textField都是read write属性。使用很简单

     

     UIView*view1 = [[UIViewalloc]initWithFrame:CGRectMake(0, 0, 320, 20)];

        view1.backgroundColor = [UIColorredColor];

        self.viewText.inputAccessoryView= view1;

     

    inputView就是显示键盘的view,如果重写这个view则,不再弹出键盘,而是弹出自己的view.

     

    在 UIWebView 状态下,重写WebView的子类,赋予inputAccessView,重写getter setter方法,最终失败,没有起作用,网上搜索找到了一个隐藏inputAccessView的方法,先看看怎么隐藏的然后再考虑怎么写inputAccessView:

    -(void)viewWillAppear:(BOOL)animated{

        [[NSNotificationCenterdefaultCenter] addObserver:self

                                                 selector:@selector(keyboardWillShow:)

                                                     name:UIKeyboardWillShowNotification

                                                   object:nil];

    }

     

    - (void)keyboardWillShow:(NSNotification *)note {

        [selfperformSelector:@selector(removeBar) withObject:nilafterDelay:0];

    }

    - (void)removeBar {

        // Locate non-UIWindow.

        UIWindow *keyboardWindow = nil;

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

            if (![[testWindow class] isEqual:[UIWindow class]]) {

                keyboardWindow = testWindow;

                break;

            }

        }

        

        // Locate UIWebFormView.

        for (UIView *formView in [keyboardWindow subviews]) {

            // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.

            if ([[formView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {

                for (UIView *subView in [formView subviews]) {

                    if ([[subView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {

                        [subView removeFromSuperview]; //这个view就是现在的inputAccessView,它的高度是44

                    }

                    elseif([[subView description] rangeOfString:@"UIImageView"].location != NSNotFound){

                        // remove the line above the input accessory view (changing the frame)

                        [subView setFrame:CGRectZero];

                    }

                }

            }

        }

    }

    现在来看,咱们找到了怎么删除这个inputAccessView的方法    [subView removeFromSuperview];  那么我直接改写这个subView呢?那样不就改了inputAccessView了么,事实上没有,这样没有效果,没有效果是吧,那就戴面具,直接写个view,然后 [subView addSubView:view]; OK这个方法可行。

  • 相关阅读:
    bootstrap 基本页面元素,代码,列表
    Servlet 获取IllegelStateException
    Servlet RequestDispatcher需要注意的情况
    每一个Servlet只有一个实例,多个线程
    Servlet中进行context属性的同步
    servlet中的8个Listener
    Spring AOP切面的时候参数的传递
    C#中StreamReader读取中文时出现乱码问题总结
    开源 免费 java CMS
    測试设计及自己主动化全景图
  • 原文地址:https://www.cnblogs.com/superhappy/p/3102528.html
Copyright © 2011-2022 走看看