草庐IT

objective-c - NSTimer 是线程安全的吗?

我有一个间隔为1/4秒的重复计时器。我正在这样初始化它:[NSTimerscheduledTimerWithTimeInterval:0.25target:selfselector:@selector(toggleCams)userInfo:nilrepeats:YES];这是同步发生的吗?换句话说,我能保证不会在调用toggleCams的同时调用同一个类中的另一个方法吗? 最佳答案 NSTimers实际上只是定期将事件触发到封闭的NSRunLoop中,每个线程都有(或应该有)。因此,如果您有一个子(或后台)进程在不同的线程中运行,

ios - NSTimer 用户信息。对象如何传递给选择器?

我有这个代码:-(void)startRotation:(RDUtilitiesBarRotation)mode{rotationTimer=[NSTimerscheduledTimerWithTimeInterval:0.1ftarget:selfselector:@selector(rotateSelectedItem:)userInfo:[NSNumbernumberWithInt:mode]repeats:YES];}-(void)rotateSelectedItem:(NSNumber*)sender{floatcurrAngle=[selectedItemcurrentRo

ios - 当我更改时间间隔的值时,如何更新我的 NSTimer

我有一个NSTtimer实现并且工作正常。我还将时间间隔参数连接到iPhone的UISlider。但是,当我更改它的值时,NSTimer仍在以原始时间间隔运行,它不会更新。我如何实现NSTimer并让它随着我的UISlider值的变化而改变它的时间间隔。下面是我用于NSTimer的行。[NSTimerscheduledTimerWithTimeInterval:mySlider.valuetarget:selfselector:@selector(myMethod)userInfo:nilrepeats:YES];我希望它用UISlider的值不断更新它的时间间隔。

ios - 不使用 dispatch_async 和重复 NSTimer 调用的方法

我正在开发一个应用程序,我想在其中使用dispatch_async在单独的队列中调用方法。我想在一定时间间隔后重复调用该方法。但是该方法没有被调用。不知道怎么回事。这是我的代码:dispatch_async(NotificationQueue,^{NSLog(@"insidequeue");timer=[NSTimerscheduledTimerWithTimeInterval:20.0target:selfselector:@selector(gettingNotification)userInfo:nilrepeats:YES];dispatch_async(dispatch_ge

ios - UIScrollView 在滚动时暂停 NSTimer

我有一个UIScrollView,它有一系列快速更新数字的标签(每.06秒)。然而,当ScrollView移动时,NSTimer暂停并且在滚动和弹性动画完成之前不会继续。我怎样才能避免这种情况并让NSTimer运行而不考虑ScrollView的状态? 最佳答案 解决此问题的一种简单方法是将NSTimer添加到mainRunLoop中。[[NSRunLoopmainRunLoop]addTimer:timerforMode:NSRunLoopCommonModes];要从安装它的所有运行循环模式中删除计时器,请向计时器发送invali

iphone - 将 NSTimer 设置为在将来触发一次

如何将NSTimer设置为在将来触发一次(比如30秒)。到目前为止,我只是设法将其设置为立即触发,然后每隔一段时间触发一次。 最佳答案 您要使用的方法是:+(NSTimer*)scheduledTimerWithTimeInterval:(NSTimeInterval)secondstarget:(id)targetselector:(SEL)aSelectoruserInfo:(id)userInforepeats:(BOOL)repeats使用repeats==NO参数和seconds==30。这将创建计时器并安排它。它只会在3

ios - 添加 scheduledTimerWithTimeInterval 时,NSTimer 不触发选择器

我有这样的代码片段:m_timer=[NSTimerscheduledTimerWithTimeInterval:timeOutInSecondstarget:selfselector:@selector(activityIndicatorTimer:)userInfo:nilrepeats:NO];当我这样调用它时,选择器不会在给定的timeOutInSeconds后触发。但是,如果我将其修改为如下所示,则选择器将被调用两次。NSLog(@"Timerset");m_timer=[NSTimerscheduledTimerWithTimeInterval:timeOutInSecon

iphone - NSTimer 可靠的替代品

我有一个应用程序,它应该每1秒记录一次某些事情,我目前正在使用NSTimer,但是如果我的应用程序转换屏幕(或几乎任何其他东西,真的),它会减慢计时器有点导致读数不准确。什么是可靠的替代品?我目前的代码如下:timer=[NSTimerscheduledTimerWithTimeInterval:1.0target:selfselector:@selector(update)userInfo:nilrepeats:YES]; 最佳答案 NSTimer永远不能保证准时触发。但是您可以比现在更可靠地使用NSTimer。当您使用sched

swift - NSTimers swift 不会开火

我有3个NSTimers:vartimer=NSTimer()varscoreTimer=NSTimer()vargameTmer=NSTimer()然后在“viewDidLoad”中:varsel=Selector("testFunc:")timer=NSTimer.scheduledTimerWithTimeInterval(1,target:self,selector:sel,userInfo:nil,repeats:true)scoreTimer=NSTimer.scheduledTimerWithTimeInterval(0.1,target:self,selector:se

swift - NSTimer 重复快速的方式

你好,我有一个关于NSTimer.scheduledTimerWithTimeInterval的问题。我将它设置为间隔两次-但是它每2秒重复一次。有谁知道我做错了什么?NSTimer.scheduledTimerWithTimeInterval(2.0,target:self,selector:Selector("updateAllHuds"),userInfo:nil,repeats:true)funcupdateAllHuds(){self.starTimer-=1self.builtTimer-=1self.gravityTimer-=1ifself.powerStar.text