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

    }

  • 相关阅读:
    小儿吃鸡蛋食积案
    女子经前胀痛脸上红斑案
    小儿外感咳嗽咽痛案
    顽固偏头痛案
    交通心肾治失眠
    小儿扁桃体高热兼咳嗽案
    过敏疾患与太少两感相合
    经前乳胀案
    女子黃带案
    小儿外感后频繁眨眼案
  • 原文地址:https://www.cnblogs.com/NatureZhang/p/3669936.html
Copyright © 2011-2022 走看看