在代码中,我有类似这样的东西,当键盘确实出现在屏幕上时会调用它。
scrollView.scrollRectToVisible(blikCodeView.frame, animated: true)
尽管 blikCodeView
根本不可见(因为它被当前显示的键盘覆盖),但它不会向上滚动以使其可见。为什么?
答案 0 :(得分:0)
试试这个
let rScreenHeight = UIScreen.main.bounds.height - 260//keyboard height as 8 & SE
let newY = rScreenHeight - txt.frame.height - 16
let y = scrollView.height - newY
let newOffSet = CGPoint(x: 0, y: y)
scrollView.setContentOffset(newOffSet, animated: true)
注意:这里我设置了 txtField.autocorectionType = .no