簡體   English   中英

關於ios點擊手勢

[英]About ios tap gesture

我在標簽上添加了一個點擊手勢。 並添加一個動作來更改它的文本。 但是當我點擊那個標簽時,它沒有任何變化。

在此處輸入圖片說明

默認情況下,標簽 UserInteraction 變為禁用。 啟用標簽用戶交互,如下所示:

label.isUserInteractionEnabled = true

如果未調用您的操作方法,請確保啟用標簽的 userInteraction。

self.lblReportDateTime.userInteractionEnabled = true

它可能會幫助你.... :)

UILabels 不是默認設置為接受來自用戶的觸摸,它們通常用於顯示某些文本。

如果您想在 UILabel 上使用 UITapGesture,則必須在 UILabel 上將userInteractionEnable屬性設置為 true

您可以設置如下屬性

斯威夫特 3.0

yourLable.isUserInteractionEnabled = true

斯威夫特 2.3

yourLable.userInteractionEnabled = true

目標 - C 版本

[yourLable setUserInteractionEnabled:YES];

嘗試這個:

class DetailViewController: UIViewController {

    @IBOutlet weak var label: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        ...

        let tap = UITapGestureRecognizer(target: self, action: #selector(DetailViewController.tapFunction))
        label.isUserInteractionEnabled = true
        label.addGestureRecognizer(tap)
    }

    func tapFunction(sender:UITapGestureRecognizer) {
        print("tap working")
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM