zoukankan      html  css  js  c++  java
  • [Swift通天遁地]三、手势与图表-(1)监听屏幕上触摸事件的各种状态

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(shanqingyongzhi)
    ➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/10207918.html 
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    目录:[Swift]通天遁地Swift

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

    在项目导航区,打开视图控制器的代码文件【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 }
  • 相关阅读:
    进程(第三部分)
    02_jni_hello_c函数介绍
    01_ndk目录介绍
    00_前情回顾
    06_锅炉压力案例_progressbar实现
    05_锅炉压力案例_java实现
    ASP.NET MVC的过滤器笔记
    ASP.NET MVC的过滤器笔记
    ASP.NET MVC的过滤器笔记
    ASP.NET MVC的过滤器笔记
  • 原文地址:https://www.cnblogs.com/strengthen/p/10207918.html
Copyright © 2011-2022 走看看