★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-kuhrqqdd-kq.html
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
目錄:[Swift]通天遁地Swiftgit
本文將演示監聽屏幕上觸摸事件的各類狀態。github
在項目導航區,打開視圖控制器的代碼文件【ViewController.swift】swift
如今開始編寫代碼,監聽屏幕上的觸摸事件的各類狀態。微信
1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from a nib. 8 9 } 10 11 //添加一個方法,用來監聽手指按下時的事件 12 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 13 //當手指在屏幕上剛剛按下時,在控制檯輸出日誌信息。 14 print("touchesBegan"); 15 } 16 17 //添加一個方法,用來監聽手指移動時的事件 18 override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { 19 //當手指在屏幕上剛剛按下並移動時,在控制檯輸出日誌信息。 20 print("touchesMoved"); 21 } 22 23 //添加一個方法,用來監聽手指移動結束,離開屏幕時的事件 24 override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 25 //當手指移動結束時,離開屏幕時,在控制檯輸出日誌信息。 26 print("touchesEnded"); 27 } 28 29 //添加一個方法,用來監聽手勢被取消的事件。例如手指子啊移動時,忽然有電話接入時的狀況 30 override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { 31 //當手勢被取消時,在控制檯輸出日誌信息。 32 print("touchesCancelled"); 33 } 34 35 override func didReceiveMemoryWarning() { 36 super.didReceiveMemoryWarning() 37 // Dispose of any resources that can be recreated. 38 } 39 }