動態獲取鍵盤高度(鍵盤擋住輸入框)

Henry Huang
1 min readAug 16, 2018

當畫面上有元件在畫面底部或畫面下半部分,鍵盤又出現時,常常發生元件被鍵盤擋住的情況,此方法就是要來解決這個困擾,動態獲取鍵盤高度並以UIView.animateKeyframes動畫展現。

成果畫面:

有一個名稱為OK的Button固定在畫面最下方,當鍵盤出現及消失時都會隨著鍵盤高度移動。

擴展UIView

在viewDidLoad裡就可以讓okBtn呼叫方法

override func viewDidLoad() {    super.viewDidLoad()    okBtn.bindToKeyboard()}

完成。

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Henry Huang
Henry Huang

Written by Henry Huang

大學讀企管/退伍後在業務圈打滾6年後突然有一天決定投入完全沒接觸過的程式設計/目前為一位iOS Developer/熱愛NBA/dafu1231@gmail.com

No responses yet

Write a response