我有一个计时器:
[NSTimer scheduledTimerWithTimeInterval:(float)jpegInterval/1000 target:self selector:@selector(jpegDownloaderSelector:) userInfo:url repeats:YES];
jpegDownloaderSelector 执行从 url 获取图像并将其设置在 imageView 中,如下所示:
-(void) jpegDownloaderSelector:(NSTimer*)timer{
[self performSelectorInBackground:@selector(jpegDownloader:) withObject:(NSString*)[timer userInfo]];
}
-(void) jpegDownloader:(NSString*)imageUrl{
dispatch_async(dispatch_get_main_queue(), ^{
imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://10.8.9.100:509/jpeg"]];
imageView.image = [UIImage imageWithData:imgData];
});
}
我还用gestureRecognizer设置了imageView
[imageView addGestureRecognizer:singleTapRecognizer];
[imageView addGestureRecognizer:doubleTapRecognizer];
其中识别器定义是:
singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(functoCall:)];
singleTapRecognizer.numberOfTapsRequired = 1;
singleTapRecognizer.numberOfTouchesRequired = 1;
doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(funcToCall2:)];
doubleTapRecognizer.numberOfTapsRequired = 2;
doubleTapRecognizer.numberOfTouchesRequired = 1;
我遇到的问题是,当计时器启动时,我双击 imageView,双击识别器没有响应,而是单击响应。
如果我将计时器重复参数设置为 NO,则双击响应。因此,我怀疑由于运行计时器调用的后台功能,双击没有响应。
任何人都建议我可以实现后台功能并且识别双击没有问题。