点击计数器和单击拖拽

2017-11-27  本文已影响0人  疯恋少年郎

在view被点击和拖拽是,会自动调用一下方法,视图被隐藏,设置为透明是不会调用。

默认情况下,一个视图会被配置只接受单个手指方法,多手指点击需要设置//self.view.multipleTouchEnabled=YES; //打开此功能后无论是单个手指还是多个手指手势,都会被发送到触摸通知方法

需要监控视图中的点击事件,在视图控制器中添加以下方法

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event;

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent*)event;

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event;

一个例子

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event

{NSLog(@"tap");

/*UITouch *touch=[touches anyObject];

CGPoint point=[touch locationInView:self.view];

NSUInteger taps=[touch tapCount];

NSLog(@"%s tap at %f,%f tap count :%d",(taps==1)?"Single":(taps==2)?"bouble":"triple+",point.x,point.y,taps);

*/

UITouch*touch=[touchesanyObject];

CGPointpoint=[touchlocationInView:self.view];

NSIntegerinter=[touchtapCount];

[supertouchesBegan:toucheswithEvent:event];

NSLog(@"%ld",inter);

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent*)event

{

UITouch*touch=[touchesanyObject];

CGPointpoint=[touchlocationInView:self.view];

CGPointold=[touchpreciseLocationInView:self.view];

[supertouchesMoved:toucheswithEvent:event];

NSLog(@"finger move form %f %f to %f,%f",old.x,old.y,point.x,point.y);

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event

{

UITouch*touch=[touchesanyObject];

CGPointlocation=[touchlocationInView:self.view];

[supertouchesEnded:toucheswithEvent:event];

NSLog(@"tap end at %f,%f ",location.x,location.y);

}

上一篇 下一篇

猜你喜欢

热点阅读