加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

[Swift通天遁地]三、手势与图表-(1)监听屏幕上触摸事件的各种状

发布时间:2020-12-14 05:07:39 所属栏目:百科 来源:网络整理
导读:本文将演示监听屏幕上触摸事件的各种状态。 在项目导航区,打开视图控制器的代码文件【ViewController.swift】 现在开始编写代码,监听屏幕上的触摸事件的各种状态。 1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDi

本文将演示监听屏幕上触摸事件的各种状态。

在项目导航区,打开视图控制器的代码文件【ViewController.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 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读