I'm generating a KeyboardView
that slides up vertically and then occupies the bottom 1/3 of a view that is used to generate it:
class KeyboardView: UIView {
private var width: CGFloat!
private var height: CGFloat!
init(withinView view: UIView) {
super.init(frame: view.frame)
configureKeyboard()
}
private func configureKeyboard() {
width = frame.width
height = frame.height * 0.33
center = CGPoint(x: width / 2, y: frame.height - halfHeight)
let origin = CGPoint(x: center.x - halfWidth, y: (center.y - halfHeight) + height)
let size = CGSize(width: width, height: height)
frame = CGRect(origin: origin, size: size)
isUserInteractionEnabled = true
}
}
I then add the keys of this keyboard as UIButton
instances after the configureKeyboard
method has been called.
However, when running this code on, say, an iPhoneX the keys of this keyboard are not within the so-called safe area of the iPhone screen.
Should I be adjusting the frame.origin
value to accommodate the bottom inset? i.e.
frame.origin.y += UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0.0
or is there another way to achieve this programatically?
Thanks for any help, still adjusting to using auto layout.