简体   繁体   English

执行UIGesture操作时,NSTimer暂停了一段时间

[英]NSTimer is pausing a while when UIGesture action performed

NSTimer is pausing a while an then again it is starting when UIGesture action performed. NSTimer暂停片刻,然后在执行UIGesture操作时再次开始。

I am developing an iOS application where I have to trigger the NSTimer repeatedly for every 0.5 seconds and based on that timer I'm moving a song progress bar. 我正在开发一个iOS应用程序,在该应用程序中,我必须每0.5秒重复触发一次NSTimer,并基于该计时器移动歌曲进度条。 And also handling touch events when user touching on some images which I kept on the same view. 当用户触摸我保持在同一视图上的某些图像时,还可以处理触摸事件。 I am seeing when user touches the images, the timer for moving the progress bar is stopping a little while and continues again. 我看到当用户触摸图像时,用于移动进度栏的计时器会停止一会儿,然后再次继续。

Are there any problem that we can't handle timer and touch events at the same time in the same view? 是否存在无法在同一视图中同时处理计时器和触摸事件的问题?

My code for timer 我的计时器代码

myTimer = [NSTimer scheduledTimerWithTimeInterval:timeinterval target:self selector:@selector(updatplayer:) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:myTimer forMode:NSRunLoopCommonModes];

This is a common issue with NSTimer. 这是NSTimer的常见问题。 While you can play with run loop modes to improve things, a nicer solution is to switch to GCD timers. 虽然您可以使用运行循环模式进行改进,但是更好的解决方案是切换到GCD计时器。 See RNTimer for an example. 有关示例 ,请参见RNTimer See the docs on dispatch_source_create for more information. 有关更多信息,请参见dispatch_source_create上的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM