簡體   English   中英

如何使用touchesBegan和touchesEnded?

[英]how to use touchesBegan and touchesEnded?

我在ViewController上添加了以下代碼

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    print("started")
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    print("ended")
}

但它根本不打印任何消息。

UIResponder類是用於響應和處理事件的抽象接口Apple API參考

UIWindow,UIViewController,UIView是UIResponder的子類

如果要使用touchesBegantouchesEnded ,請覆蓋它

觸摸事件關注響應者鏈,請參閱蘋果文檔

在此處輸入圖片說明

發生了一些觸摸事件,並且您的ViewController的視圖成為下一個響應者,並且成功進行了hittest touchesBegan在觸摸開始時被調用,而touchesEnded被稱為touch結束

暫無
暫無

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

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