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这个方法可行。

posted @ 2013-05-27 21:22  SuperHappy  阅读(2432)  评论(0编辑  收藏  举报