3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SwiftUI でキーボードの表示/非表示に応じて背後のコンテンツの高さを調整する

Last updated at Posted at 2020-05-04

概要

SwiftUI でキーボードを表示したときに、背景のコンテンツの高さがよろしく調整されず、キーボードの背後に隠れてしまうので、自分で実装した。

Before

before.gif

After

after.gif

サンプルコード

方法

Spacer の高さをキーボードの高さにして、コンテンツを見える範囲にする戦略。

補足

  • iPad ではキーボードの表示位置が決まってないので、無効にした方が良い。
  • キーボードの高さをそのまま Spacer に渡すと、キーボードの上に 34px ぐらいの余白ができてしまうので、調整が必要。
  • キーボード上げ下げに応じたアニメーションは諦めた。

参考記事

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?