ios - iOS 有没有办法调整键盘高度?

标签 ios swift

我想更改 iOS 中小数点键盘的高度。我得到默认键盘高度和小数点键盘的黑白高度差。

func resizeKeyboard(note: NSNotification){
    let userInfo = note.userInfo!
    let duration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as! Double
    let curve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as! UInt

    var frameEnd = self.view .convert(((userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue), from: nil)

    if note.name == NSNotification.Name.UIKeyboardWillShow{
         Keyboard appears
         desiredHeight = 260
    }else if note.name == NSNotification.Name.UIKeyboardWillHide{
         Keyboard hides
         desiredHeight = 260
    }

    self.heightConstraint.constant = desiredHeight
    self.view .setNeedsLayout()

    UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions(rawValue: curve), animations: {
        self.view .setNeedsLayout()
    }, completion: nil)
}

最佳答案

您无法更改系统键盘的高度,如 documentation说,这并不总是相同的:

You should always use the information in these notifications as opposed to assuming the keyboard is a particular size or in a particular location. The size of the keyboard is not guaranteed to be the same from one input method to another and may also change between different releases of iOS.

这意味着您的代码需要查看 UIKeyboardFrameEndUserInfoKey 来确定实际的键盘高度,并调整/滚动 UI 的其余部分以适应该高度。

关于ios - iOS 有没有办法调整键盘高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48352946/

相关文章:

ios - 无法在 iPad iOS5 中为通用应用程序保留横向(iOS6 可以)

swift - Firebase 和 Swift 限制帖子编号错误

ios - 在swift中实现HMAC和SHA1加密

ios - 将replaceScene与cocos2d一起使用时的iPhone崩溃报告

ios - Swift iAd - 超过 10 个 ADBannerView 警告和 CGAffineTransformInvert 实例 : singular matrix output

ios - 为什么alert dismiss在再次触发时不起作用?

ios - 我正在尝试对 Sprite 节点对象进行一些移动

ios - Swift:UITabbarController覆盖而不覆盖 Storyboard中的TabBar

ios - 修改一个随机 NSPoint 的属性并将新版本放回 NSMutableArray

ios - 使用哪种方法在启动时设置变量?