點選到TableView時也可縮回鍵盤

Henry Huang
1 min readJul 31, 2020

--

在viewcontroller建立一個包含關鍵字@objc 的方法,裡面是執行結束編輯(縮回鍵盤)

@objc func dismisskeyboard() {  self.view.endEditing(true)}

在viewDidLoad裡加上這些

let tap = UITapGestureRecognizer(target: self, action: #selector(self.dismisskeyboard))tap.numberOfTapsRequired = 1 //只需點到1下,就會執行,設置100就是點100下才執行tap.cancelsTouchesInView = false //可讓tableView cell 也可點選,預設是truetableView.addGestureRecognizer(tap)

完成

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