使用touchesmoved时,Touchesbegan总会开火吗?

Raf*_*fal 2 iphone touchesmoved touchesbegan

我是iPhone编程的新手.我正试图做一个简单的窗口,一只猫做两声.当你点击猫图标时它应该做"miaau",当你拖过窗口(笔划)时它应该是"mrrrr".它工作,但总是当我尝试使猫mrrrrr功能TouchesBegan火和猫也做"miaaau".

怎么做才能使界面识别我只想要中风猫,而不是触摸它做第一个选项,"miaau"?

Max*_*Max 7

我建议在touchesBegan方法中添加一个NSTimer,时间间隔很短(比如0.1秒):

BOOL tap_event = NO; //ivar declared in header

-(void) touchesBegan:... {
    tap_event = YES;
    [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(checkTap:) userInfo: nil repeats: NO];
} 

-(void) checkTap:(NSTimer*) t {
     if( tap_event ) //miauu here
     tap_event = NO;
}

-(void) touchesMoved:... {
    tap_event = NO;
     //mrrrr here
}
Run Code Online (Sandbox Code Playgroud)

或者作为选项检查UIGestureRecognizers的文档