【问题标题】:Remove Keyboard Form toolbar on ios7 leaves a blur behind从 ios 7 的工具栏中删除键盘留下了模糊
【发布时间】:2013-09-16 21:23:04
【问题描述】:

我可以删除工具栏,但我的宽度与工具栏的高度模糊。

关于如何删除它的任何想法?

下面的代码是函数。这很简单。 我使用 phonegap 在 webview 中使用它。

-(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) {

            // remove the border above the toolbar in iOS 6
            [
                [possibleFormView layer] setMasksToBounds: YES];

            for (UIView * subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
                if ([
                    [subviewWhichIsPossibleFormView description] rangeOfString: @"UIWebFormAccessory"].location != NSNotFound) {
                    [subviewWhichIsPossibleFormView removeFromSuperview];

                    // http://stackoverflow.com/questions/10746998/phonegap-completely-removing-the-black-bar-from-the-iphone-keyboard/10796550#10796550
                    UIScrollView * webScroll;
                    if ([
                        [
                            [UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
                        webScroll = [
                            [self webView] scrollView];
                    } else {
                        webScroll = [
                            [
                                [self webView] subviews] lastObject];
                    }

                    CGRect newFrame = [webScroll frame];

                    float accessoryHeight = [subviewWhichIsPossibleFormView frame].size.height;
                    newFrame.size.height += accessoryHeight;

                    [subviewWhichIsPossibleFormView removeFromSuperview];
                    [webScroll setFrame: newFrame];
                }
            }
        }
    }
}

如果您遇到此问题,请务必前往 https://bugreport.apple.com 并复制 rdar://9844216

【问题讨论】:

  • 我已经添加了screenie :-)
  • 您是否使用此代码在 iPhone 5s 上测试过您的应用程序?工作正常吗?
  • 我找到了 iOS 8 的解决方案。你可以在这里查看:[ iOS 8 - Remove Previous/Next/Done UIKeyboard Toolbar inside a UIWebView][1] [1]: stackoverflow.com/questions/25022089/…跨度>
  • 我找到了 iOS 8 的解决方案。你可以在这里查看:iOS 8 - Remove Previous/Next/Done UIKeyboard Toolbar inside a UIWebView stackoverflow.com/questions/25022089/…

标签: objective-c cordova ios7


【解决方案1】:
- (void)removeKeyboardTopBar {
// 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) {

            // HERE!! hides the backdrop (iOS 7)
            if ([[peripheralView description] hasPrefix:@"<UIKBInputBackdropView"]) {
                [[peripheralView layer] setOpacity:0.0];
            }
            // hides the accessory bar
            if ([[peripheralView description] hasPrefix:@"<UIWebFormAccessory"]) {
                // remove the extra scroll space for the form accessory bar
                CGRect newFrame = diaryEditorView.scrollView.frame;
                newFrame.size.height += peripheralView.frame.size.height;
                diaryEditorView.scrollView.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];
            }
        }
    }
}

}

【讨论】:

  • 好答案。不过可以改进。有两种背景视图:一种在表单工具栏下,另一种在键盘本身下。您的解决方案隐藏了两个背景视图。结果,键盘变得透明——这是一个不受欢迎的副作用。我会稍微修改您的解决方案:仅隐藏工具栏下的背景(其y 坐标为0)。例如,CGRect rect = peripheralView.frame; if (rect.origin.y == 0) [[peripheralView layer] setOpacity:0.0];
  • 我仍然有白色或黑色背景,具体取决于 webview 的颜色。我认为 webview 没有调整到正确的大小。
  • 只有当 viewport meta height=device-height 被设置时,这才适用于任何 phonegap 版本
  • Alexander 的 origin.y 检查对我来说效果很好。这似乎在 iOS 7.1 上尤为重要。
  • ios 菜鸟在这里。有谁知道如何修复“使用未声明的标识符'diaryEditorView'”错误?谢谢
【解决方案2】:

User2038156 的回答在 7.1 上对我来说效果不佳,因为它还排除了键盘后面的面板,使其完全透明。要仅删除额外区域的背景,您可以使用以下代码:

- (void)removeBar {
    if(self.isHidingDoneBar){
        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) {

                    // HERE!! hides the backdrop (iOS 7)
                    if ([[peripheralView description] hasPrefix:@"<UIKBInputBackdropView"] && peripheralView.frame.size.height == 44) {
                        [[peripheralView layer] setOpacity:0.0];
                    }
                    // hides the accessory bar
                    if ([[peripheralView description] hasPrefix:@"<UIWebFormAccessory"]) {
                        // remove the extra scroll space for the form accessory bar
                        CGRect newFrame = webView.scrollView.frame;
                        newFrame.size.height += peripheralView.frame.size.height;
                        webView.scrollView.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];
                    }
                }
            }
        }
    }
}

【讨论】:

  • 我遇到了同样的问题。这解决了它!谢谢! if ([[peripheralView description] hasPrefix:@"
  • 我正在开发 Phonegap 应用程序。你能告诉我应该在哪里添加这段代码吗?
  • 在 iOS7 上运行良好,但在 iOS8 上我需要这个...有什么建议吗?
【解决方案3】:

这是一种快速完成相同操作的好方法,只需一行代码,在您的自定义 UIResponder 中完成:

public override func becomeFirstResponder() -> Bool {

     if !self.isEditing {

            super.becomeFirstResponder()
            //TODO: Do some sanity checks here , this is a hack to remove the backdrop on iOS 7.0 +
            self.inputView?.superview?.subviews.first?.removeFromSuperview()

     }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-24
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    • 1970-01-01
    相关资源
    最近更新 更多