【问题标题】:How to remove top bar of the keyboard in ios 7如何在 iOS 7 中删除键盘的顶部栏
【发布时间】:2013-11-21 14:51:57
【问题描述】:

在我的程序中,我将UIWebView 与可编辑的 div 一起用于富文本编辑器。我需要删除键盘的顶栏。

我使用下面的代码 - 它只删除下一个/上一个按钮 我想删除完整的顶栏。

- (void)removeBar {
    UIWindow *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        if (![[testWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = testWindow;
            break;
        }
    }

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

【问题讨论】:

  • 老实说,我不确定 Apple 是否会允许您像这样使用本机键盘。提交时可能会被拒绝。
  • 文本视图和文本字段不会出现。我需要没有键盘工具栏
  • 无论如何弄乱键盘都会被拒绝,即使它只是摆脱了键盘顶部的工具栏。我建议审查您的设计计划,因为我真的认为这是不允许的。对不起。
  • iOS8 上已经不行了。
  • 我找到了iOS 8的解决方案。你可以在这里查看:cocoainios.blogspot.in/2014/11/…

标签: ios ios7


【解决方案1】:

我找到了适用于 iOS 8 的解决方案。您可以在此处查看:[ iOS 8 - Remove Previous/Next/Done UIKeyboard Toolbar inside a UIWebView][1]

您可以尝试改进这一点。尝试在您的 UIKeyboardDidShowNotification 事件处理程序中调用此函数。

希望这会有所帮助... 这是附件中的视图级别: (UIWebFormAccessory) -> (UIToolbar) -> (UIImageView,UIToolbarButton,UIToolbarButton)

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

                }
            }

        }
    }


}
}

【讨论】:

    【解决方案2】:

    here 有一个解决方案。

    该答案包括一个名为 removeKeyboardTopBar 的函数,应在 UIKeyboardWillShowNotification 上调用该函数。

    1. 收听通知:

      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
      
    2. 在通知上,延迟后调用该函数。延迟是必要的,以确保在函数运行之前对象存在(因为我们在键盘 will 显示而不是键盘 did 显示上调用它。

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

    【讨论】:

      【解决方案3】:

      据我所知,键盘顶部似乎添加了一个 inputAccessoryView。否则,我不确定它为什么会出现。无论如何,如果是这种情况,那么无论您分配 firstResponder 以将其 inputAccessoryView 设置为 nil:

      someObjectWithFirstResponder.inputAccessoryView = nil;
      

      编辑:看起来 UIWebView 设置了 inputAccessoryView 本身,但如果它实际上正在接收 firstResponder,那么您应该能够覆盖 inputAccessoryView。如果将其设置为 nil 导致它默认返回到您尝试删除的 inputAccessoryView,那么您可以尝试将其设置为空视图:

      someObjectWithFirstResponder.inputAccessoryView = [UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
      

      EDIT此方法不适用于 iOS 8.0 及更高版本。

      【讨论】:

      • 你是对的。我已经在 Obj-C 和 Swift 中尝试过,但似乎都没有删除它。我已经更新了我的初始回复,表明该方法在 iOS 8 中不起作用。如果找到适用的解决方案,我一定会更新我的回复。
      • @AronCrittendon 我找到了适用于 iOS 8 的解决方案。您可以在这里查看:cocoainios.blogspot.in/2014/11/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多