2011-12-12 47 views
6

我已經在IOS 5中使用了UIWebview。我嘗試設置contenteditable="true"以使uiwebview可編輯。如何從虛擬鍵盤中刪除prev next按鈕IOS

我的應用程序的screenshoot是在這個環節How do you remove the Next and Prev buttons from virtual keyboard in Sencha Touch/Phonegap application類似的圖像,

enter image description here

我的問題是,我想從鍵盤刪除此分組&下一個按鈕,但我不知道怎麼辦。有些身體可以幫助我嗎?

謝謝

+0

我發現的iOS 8.您的解決方案可以在這裏檢查:iOS 8 - 刪除UIWebView中的上一個/下一個/完成UIKeyboard工具欄http://stackoverflow.com/questions/25022089/remove-next-previous-buttons-inputaccessory-for-custom-keyboard-in-ios8 – Gaurav

回答

11

這是一個古老的答案,不再在iOS 9.工作對於一個更新的解決方案,請參閱我的回答here


這是一個灰色區域,但肯定可行。

在這裏看到:http://ios-blog.co.uk/iphone-development-tutorials/rich-text-editing-a-simple-start-part-1/

註冊的通知上鍵盤顯示:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 

然後:

- (void)keyboardWillShow:(NSNotification *)note { 
    [self performSelector:@selector(removeBar) withObject:nil afterDelay: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 *possibleFormView in [keyboardWindow subviews]) {  
     // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView. 
     if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) { 
      for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) { 
       if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) { 
        [subviewWhichIsPossibleFormView removeFromSuperview]; 
       } 
      } 
     } 
    } 
} 
+0

它留下了一個空的地方,酒吧是如何刪除的? – jAckOdE

+0

您可以嘗試降低contentInset。 –

+0

hm,我還沒有試過你的方式,但是我發現如果將附件窗體的框架設置爲「空矩形」,它就可以工作。 – jAckOdE

3

刪除空白區域。

- (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 *possibleFormView in [keyboardWindow subviews]) { 
     if ([[possibleFormView description] hasPrefix:@"<UIPeripheralHostView"]) { 
      for (UIView* peripheralView in [possibleFormView subviews]) { 

       // hides the backdrop (iOS 7) 
       if ([[peripheralView description] hasPrefix:@"<UIKBInputBackdropView"]) { 
        //skip the keyboard background....hide only the toolbar background 
        if ([peripheralView frame].origin.y == 0){ 
         [[peripheralView layer] setOpacity:0.0]; 
        } 
       } 
       // hides the accessory bar 
       if ([[peripheralView description] hasPrefix:@"<UIWebFormAccessory"]) { 
        // remove the extra scroll space for the form accessory bar 
        UIScrollView *webScroll; 
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) { 
         webScroll = [[self webView] scrollView]; 
        } else { 
         webScroll = [[[self webView] subviews] lastObject]; 
        } 
        CGRect newFrame = webScroll.frame; 
        newFrame.size.height += peripheralView.frame.size.height; 
        webScroll.frame = newFrame; 

        // remove the form accessory bar 
        [peripheralView removeFromSuperview]; 
       } 
       // hides the thin grey line used to adorn the bar (iOS 6) 
       if ([[peripheralView description] hasPrefix:@"<UIImageView"]) { 
        [[peripheralView layer] setOpacity:0.0]; 
       } 
      } 
     } 
    } 
} 
1

我發現的iOS 8.解決方法您可以點擊此處查看:

-(void) removeKeyboard { 
UIWindow *keyboardWindow = nil; 
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) { 
    if (![[testWindow class] isEqual : [UIWindow class]]) { 
     keyboardWindow = testWindow; 
     break; 
    } 
} 
// Locate UIWebFormView. 
for (UIView *possibleFormView in [keyboardWindow subviews]) { 

    if ([[possibleFormView description] hasPrefix : @"<UIInputSetContainerView"]) { 
     for (UIView* peripheralView in possibleFormView.subviews) { 

      for (UIView* peripheralView_sub in peripheralView.subviews) { 


       // hides the backdrop (iOS 8) 
       if ([[peripheralView_sub description] hasPrefix : @"<UIKBInputBackdropView"] && peripheralView_sub.frame.size.height == 44) { 
        [[peripheralView_sub layer] setOpacity : 0.0]; 

       } 
       // hides the accessory bar 
       if ([[peripheralView_sub description] hasPrefix : @"<UIWebFormAccessory"]) { 


        for (UIView* UIInputViewContent_sub in peripheralView_sub.subviews) { 

         CGRect frame1 = UIInputViewContent_sub.frame; 
         frame1.size.height = 0; 
         peripheralView_sub.frame = frame1; 
         UIInputViewContent_sub.frame = frame1; 
         [[peripheralView_sub layer] setOpacity : 0.0]; 

        } 

        CGRect viewBounds = peripheralView_sub.frame; 
        viewBounds.size.height = 0; 
        peripheralView_sub.frame = viewBounds; 

       } 
      } 

     } 
    } 
} 
} 

您可以嘗試和改進這一點。嘗試在您的UIKeyboardDidShowNotification事件處理程序中調用此函數。

希望這有助於... 這是意見附件級別: (UIWebFormAccessory) - >(UIToolbar) - >(的UIImageView,UIToolbarButton,UIToolbarButton)