2012-04-02 3 views
0

Wenn die UIWebView die Tastatur zeigt, gibt es eine kleine Symbolleiste am oberen Rand (Zubehörteil), der die Tasten „getan, vorherigen, nächsten“ Derzeitdie accesory Artikel auf der Tastatur UIWebView Entfernen

hat, ich bin unter Verwendung der folgenden als Behelfslösung diese Symbolleiste zu entfernen:

https://gist.github.com/2048571

aber ich bin besorgt darüber, diese nicht in zukünftigen Versionen von iOS funktionieren könnte. Gibt es einen besseren Weg, dies zu tun?

+0

Haben Sie finden eine Lösung? – jAckOdE

+0

Leider verwende ich immer noch diese Methode. – marklar

+0

Ich versuche die Methode, die Sie hier posten, aber es funktioniert nicht auf IOS 4.3. Ich fand dieses: http://stackoverflow.com/questions/8470984/how-to-remove-prev-next-button-from-virtual-keyboard-ios/8682238#comment13460308_8682238 es funktioniert gut in iOS 4.3 und höher. – jAckOdE

Antwort

1

Zuerst hört Tastaturereignisse:

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

wenn Tastatur zeigen, entfernen Sie die Symbolleiste:

- (void)keyboardWillShow:(NSNotification *)note { 
[self performSelector:@selector(removeBar) withObject:nil afterDelay:0]; 
} 

die removeBar sich wie folgt:

- (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]; 
       } 
      } 
     } 
    } 
} 

Referenz: https://github.com/don/KeyboardToolbarRemover/blob/master/src/ios/KeyboardToolbarRemover.m

Verwandte Themen