0

これが私のコードです。キーボードの状態を管理し、キーボードの高さを取得するために KeyboardHelper ライブラリと、SnapKit を使用しています。キーボードをトリガーするテキスト フィールドがあります。キーボードが表示されている場合、青いボックスをキーボードの境界より上に上げたいので、表示されます。これまでのところ、私はそうすることができませんでした。私のコードを教えてください。

private var keyboardHelper : KeyboardHelper?
let box = UIView()

override func viewDidLoad() {
    super.viewDidLoad()
    keyboardHelper = KeyboardHelper(delegate: self)

    guard let superview = self.view else {
        return
    }

    box.backgroundColor = UIColor.blue
    superview.addSubview(box)

    box.snp.makeConstraints { make in
        make.bottom.equalTo(superview.snp.bottom).offset(-16)
        make.width.equalTo(200)
        make.centerX.equalTo(superview)
        make.height.equalTo(100)
    }
}

func keyboardWillAppear(_ info: KeyboardAppearanceInfo) {
    UIView.animate(withDuration: TimeInterval(info.animationDuration), delay: 0, options: info.animationOptions, animations: {
        self.box.snp.updateConstraints({ make in
            make.bottom.equalTo(info.endFrame.size.height).offset(10)
        })
        self.box.layoutIfNeeded()
    }, completion: nil)
}
4

1 に答える 1