您的位置:首页 > 编程语言

关于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 MoveTouch
CGPoint 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 能够与用户进行交互
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: