【问题标题】:how to remove prev next button from virtual keyboard IOS如何从虚拟键盘IOS中删除prev next按钮
【发布时间】:2012-01-18 06:00:26
【问题描述】:

我在 IOS 5 中使用了 UIWebview。我尝试设置 contenteditable="true" 以使 uiwebview 可编辑。

我的应用程序的屏幕截图类似于此链接中的图像How do you remove the Next and Prev buttons from virtual keyboard in Sencha Touch / Phonegap application

我的问题是我想从键盘上删除这个上一个和下一个按钮,但我不知道怎么做。有什么身体可以帮助我吗?

谢谢

【问题讨论】:

标签: objective-c ios5 uiwebview keyboard next


【解决方案1】:

这是一个旧答案,不再适用于 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];
                }
            }
        }
    }
}

【讨论】:

  • 它在酒吧所在的地方留下了一个空白区域,你如何删除它?
  • 你可以试试降低contentInset。
  • hm,我没有尝试过你的方法,但我发现如果我将附件表单的框架设置为“空矩形”,它就可以了。
  • 这是在访问私有 API 以删除代码中的下一个/上一个吗?
  • 正如我所说,这是一个灰色地带。从技术上讲,它不是私有的。但我们正在触及 Apple 的视图层次结构。
【解决方案2】:

删除空白区域。

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

【讨论】:

    【解决方案3】:

    这是UIWebBrowserView(内部UIWebView)的inputAccessoryView,你可以破解它。

    这里是一个例子:https://gist.github.com/bjhomer/2048571

    【讨论】:

    • 比以前的解决方案干净得多。
    【解决方案4】:

    我找到了适用于 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)

    【讨论】:

      猜你喜欢
      • 2011-08-29
      • 2013-03-23
      • 2013-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      • 2010-12-31
      • 1970-01-01
      相关资源
      最近更新 更多