Swift on Xcode#11[長按短按改變狀態:UITableView、UIGestureRecognizer]

如何做到結合手勢改變編輯狀態?這篇來教你這個小技巧

前言

我還記得以前常常會有手機程式需要以長按、短按來改變編輯狀態,今天稍微研究了一下,覺得這個挺有趣的。所以也就來點小小的分享:

正文

extension

先檢查extension上的狀態:

確認好擴展裡面的func都有設定好,這些東西是不可以變動的,有點像是你已經預先擴充了這個功能

GestureRecognizer

這個時候我們要設定一下一些手勢:

以下是長按、雙擊的手勢

好了之後,記得加入tableView中。

然後在前面的事件中,再設定好你要讓什麼時候讓theTableView開啟與關閉功能。

這樣就大功告成了!

長按前
長按後,雙擊又會回到前一張圖示

小記:原先還以為這個功能會很困難,然後以為要改func的回傳狀態,但後來想想不對,這個擴展的認定功能,大概不會從func改變,應該是開起編輯模式與否的問題,後來這個小題目就迎刃而解了。

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

影山小麥機
影山小麥機

Written by 影山小麥機

本職為Mobile工程師,熱愛分享視野,也樂意站在ChatGPT的肩膀上。訂閱小麥機,收割技術、職涯、人生的難題。

No responses yet

Write a response