點(diǎn)擊計(jì)數(shù)器和單擊拖拽

在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);

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容