★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(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 }