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); // 触摸事件所在的窗口

    }

  • 相关阅读:
    BZOJ 3744 Gty的妹子序列
    BZOJ 3872 Ant colony
    BZOJ 1087 互不侵犯
    BZOJ 1070 修车
    BZOJ 2654 tree
    BZOJ 3243 向量内积
    1003 NOIP 模拟赛Day2 城市建设
    CF865D Buy Low Sell High
    CF444A DZY Loves Physics
    Luogu 4310 绝世好题
  • 原文地址:https://www.cnblogs.com/NatureZhang/p/3669936.html
Copyright © 2011-2022 走看看