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

    }

  • 相关阅读:
    POJ
    UPC-5843: 摘樱桃(最优状态递推)
    BZOJ-1088 [SCOI2005]扫雷Mine(递推+思维)
    HDU-3065 病毒侵袭持续中(AC自动机)
    BZOJ-4236 JOIOJI (map查找+思维)
    HDU-2896 病毒侵袭(AC自动机)
    Hrbust-2060 截取方案数(KMP)
    UVALive 4490 压缩DP
    UVALive 5881
    UVALive 4168
  • 原文地址:https://www.cnblogs.com/NatureZhang/p/3669936.html
Copyright © 2011-2022 走看看