zoukankan      html  css  js  c++  java
  • 触摸

      UIView支持触摸事件  因为继承于UIResponder,而且支持多点触摸,使用时需要定义UIView子类,实现触摸相关的方法

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;点击开始时执行此方法(多么见名知意)

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 触摸结束时执行

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; 在屏幕上滑动时执行

    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;当触摸序列被打断时(如电话)执行

     

    // 点击视图改变颜色

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

    {

        // touches 是一个集合 存储touche   

    //    NSLog(@"%s %d", __func__, __LINE__);

    //    NSLog(@"%@ ----- %d", touches, [touches count]);    

        UITouch *touch = [touches anyObject];// 某一个手指

        NSLog(@"%d", [touch tapCount]); // 点击次数

        NSLog(@"%f", [touch timestamp]);    

     

        self.backgroundColor = [UIColorcolorWithRed:(arc4random() % 256)/255.0green:(arc4random() % 256)/255.0blue:(arc4random() % 256)/255.0alpha:1.0];

        

        CGPoint location = [touch locationInView:self];

        NSLog(@"%.1f %.1f", location.x, location.y);

        NSLog(@"%@", touch.view);  // 触摸所在的视图

        NSLog(@"%@", touch.window); // 触摸事件所在的窗口

    }

  • 相关阅读:
    [湖北省队互测2014] 没有人的算术 (非题解)
    普及常见图论算法整理
    普及常见数据结构板子整理
    Pisano Period
    退役了
    LOJ3246 「USACO 2020.1 Platinum」Cave Paintings
    LOJ3193 「ROI 2019 Day2」机器人高尔夫球赛
    LOJ3192 「ROI 2019 Day2」课桌
    LOJ6496 「雅礼集训 2018 Day1」仙人掌
    Luogu P4518 [JSOI2018]绝地反击
  • 原文地址:https://www.cnblogs.com/NatureZhang/p/3669936.html
Copyright © 2011-2022 走看看