在view被點(diǎn)擊和拖拽是,會自動(dòng)調(diào)用一下方法,視圖被隱藏,設(shè)置為透明是不會調(diào)用。
默認(rèn)情況下,一個(gè)視圖會被配置只接受單個(gè)手指方法,多手指點(diǎn)擊需要設(shè)置//self.view.multipleTouchEnabled=YES; //打開此功能后無論是單個(gè)手指還是多個(gè)手指手勢,都會被發(fā)送到觸摸通知方法
需要監(jiān)控視圖中的點(diǎn)擊事件,在視圖控制器中添加以下方法
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event;
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent*)event;
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event;
一個(gè)例子
-(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);
}