关于touch的一些方法和代码
2015-09-01 15:39
295 查看
关于手指触摸的几个方法
//开始触摸-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"开始触摸");
}
//触摸过程中
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"触摸过程中");
}
//触摸结束
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"触摸结束");
}
//触摸取消
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"触摸取消");
}
怎样让色块随着手指的拖动移动···
@implementation MoveTouchCGPoint offsetPoint;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[touches anyObject];
offsetPoint=[touch locationInView:self];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// NSLog(@"移动");
UITouch *touch=[touches anyObject];
// NSLog(@"%@",touch);//打印每次移动的位置:相对于整个window的位置和相对于自身所在的frame的位置
//获取当前的点,相对于window的位置
CGPoint currentPoint =[touch locationInView:self.window];
// NSLog(@"%@",NSStringFromCGPoint(currentPoint))//打印当前位置
self.frame=CGRectMake(currentPoint.x-offsetPoint.x, currentPoint.y-offset.y, self.frame.size.width,
self.frame.size.height);
}
@end
响应者链
响应者链事件处理的顺序与触摸检测查询相反。
阻断,无法完成检测查询。
(BOOL)
userInteractionEnabled
YES 停止与用户进行交互
NO 能够与用户进行交互
相关文章推荐
- C++纯虚函数 virtual =0
- CSharpGL(2)设计和使用场景元素及常用接口
- FTP异常 -- it.sauronsoftware.ftp4j.FTPException [code=550, message= Directory not found] (System.err)
- Opencv_Python学习笔记--OpenCV中的GUI特性
- Spring 依赖注入(DI)
- C语言中建立和删除文件连接的相关函数讲解
- Eclipse配置GitHub
- java的构造方法
- django中添加用户
- maven + eclipse 问题记录
- java中split以"."分隔和以"\"分隔
- SMTP基本原理与C++实现向多人发送邮件
- C语言利用链表实现有效内存管理
- java 8 修改环境变量问题
- Java——equals方法与== 及其重写
- Java中Integer的变量比较源码解析
- Java中Integer的变量比较源码解析
- ssh批量登录并执行命令(python实现)
- Java输入输出流
- 使用tornado的gen.coroutine进行异步编程