如何从 UITextField 键盘中删除模糊

How to remove blur from UITextField keyboard

我有一个显示国家列表的 UIPickerView,我希望 PickerView 完全没有背景,也没有模糊效果,我设法用这条线去除了颜色代码:

picker.backgroundColor = UIColor.clear

但是,我无法删除模糊效果。是否可以删除它?

更新:

我刚刚意识到模糊效果来自 UITextField 而不是来自 UIPickerView,但仍然找不到解决方法。

我发现了一个有效的技巧,我没有尝试从键盘上移除模糊,而是使用 UIPickerView 的背景颜色更改为匹配 UIView 背景颜色,使用 numberOfRowsInComponent函数:

picker.backgroundColor = UIColor.black

如果您为 UIView 背景使用渐变色,您可以使用此行:

picker.addGradientBackground(firstColor: UIColor.black, secondColor: UIColor.white)

但您必须正确管理颜色才能获得最佳效果。

此外,如果您只有颜色的十六进制值,您可以使用 this site

轻松将它们转换为 UIColor

补充说明:

在我的例子中,我为我的 UIView 背景使用了渐变颜色,并且在键盘出现时移动 UITextField 的功能,您可以找到 here,谢天谢地让它变得更容易,因为我只需要为 UIPickerView 背景使用一种颜色,即 UIView 背景最底部的颜色。

HTH

我有同样的问题,并在我的自定义 inputView 下方找到了隐藏模糊视图的解决方案。 您可以添加观察者键盘的通知将显示,并隐藏模糊视图。 我还测试了 iOS 9 -> 12。 希望这可以帮助。

NotificationCenter.default.addObserver(
        self,
        selector: #selector(self.keyboardWillShowNotification(_:)),
        name: UIResponder.keyboardWillShowNotification,
        object: nil
    )

@objc func keyboardWillShowNotification(_ notification: Notification) {
    guard let superView = inputView?.superview else { return }
    for childView in superView.subviews where childView != inputView {
        childView.isHidden = true
    }
}

结果: Simulator 5s on iOS 12