触摸

摘要:
UIView支持触摸事件,因为它继承自UIResponder并支持多点触摸。使用它时,需要定义UIView子类来实现与触摸相关的方法-(void)touchesBegan:(NSSet*)touchesWithEvent:(UIEvent*)event;单击“开始”执行此方法(请参见名称和含义)-(void)touchesEnded:(NSSet*)touchesWithEvent:(UIEvent*)eve

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

}

免责声明:文章转载自《触摸》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ElementUI的el-select怎样实现下拉多选并实现给下拉框赋值和获取值redis 参数配置总结下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

移动设备上的触摸事件

在 iOS 的 Safari 浏览器中,增加了一些触摸(touch)事件和手势(gesture)事件,这里总结一下它们的用法。 一、触摸事件 iOS 浏览器的触摸事件包括 touchstart,touchmove,touchend,touchcancel。Android 的浏览器中也同样支持这些事件。这些触摸事件的触发条件如下: touchstart:手...

extjs学习笔记--ExtJS框架基础:事件模型及其常用功能

前言 工作中用ExtJS有一段时间了,Ext丰富的UI组件大大的提高了开发B/S应用的效率。虽然近期工作中天天都用到ExtJS,但很少对ExtJS框架原理性的东西进行过深入学习,这两天花了些时间学习了下。我并不推荐大家去研究ExtJS框架的源码,虽然可以学习其中的思想和原理,但太浪费精力了,除非你要自己写框架。 对于ExtJS这种框架,非遇到“杂症”的时候...

用pygame实现打飞机游戏-6-显示敌机

1 #coding=utf-8 2 importpygame 3 #导入pygame模块 4 from pygame.locals import * 5 #导入检测键盘的子模块 6 importtime 7 classAircraftCoordinate(object): 8 def __init__(self,screen): 9...

深入Android开发之--理解View#onTouchEvent

一:前言 View是Android中最基本的UI单元. 当一个View接收到了触碰事件时,会调用其onTouchEvent方法.方法声明如下: ? 1 2 3 4 5 6 7 /** * Implement this method to handle touch screen motion events. * * @param even...

IE和Firefox的兼容问题

IE和Firefox的兼容问题 本文摘自:http://blog.csdn.net/powerglover/archive/2009/01/15/3789631.aspx 1、Event的问题 在ie中我们可以直接使用event变量,但是在firefox下由于event是局部变量,firefox下我们可以事件绑定到元素上 例如 <input type...

12.手机端如何拖动组件--从零起步实现基于Html5的WEB设计器Jquery插件(含源码)

 前面示例都只是展示在桌面浏览器显示,当用手机浏览器打开时发现无法拖动元素,虽然实际业务上,手机也只是用来查看的,但为了论证手机上的触摸事件,我还是在本节做个演示。 手机上触控有三个重要事件touchstart,touchmove,touchend,分别表示开始触摸,移动,及结束,与鼠标的mousedown,mousemove,mouseup对应。 基于...