nstimer

How do I change timing for NSTimer?

梦想与她 提交于 2019-12-03 10:57:41
I have the following code: timer = [[NSTimer scheduledTimerWithTimeInterval:0.50 target:self selector:@selector(onTimer) userInfo:nil repeats:YES] retain]; -(void) onTimer { } After every 0.50 seconds the OnTimer method is called. But now I want to increment the time-interval. That means: OnTimer calls after 0.55 OnTimer calls after 0.60 OnTimer calls after 0.65 OnTimer calls after 0.70 OnTimer calls after 0.75 & so on. Is there any solution for this?? I have tried lot but its not working. Sure you can do this. Change repeats:YES to repeats:NO so that the timer doesn't repeat, and then in

NSTimer behavior in background (addTimer:, beginBackgroundTaskWithExpirationHandler:)

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Xcode 6.3.1 ARC Enabled, for iOS 8.3 I need help understanding a strange behavior that I encounter while trying to maintain a singleton shared timer in my application after it enters background. Previously I did not care for this NSTimer as it was updated with user location in the background using background location services. However, I would like to address the case where the user rejects location updates while in background or location updates all together. The location and the timer go hand in hand for my app. I worked through

iPhone: How to code a reducing countdown timer?

血红的双手。 提交于 2019-12-03 08:55:39
I want to show a countdown timer using a UILabel which will start from 5 and reduces by 1 every second like: 5 4 3 2 1 and finally hides the label when it reaches 0. I tried to code it using NSTimer scheduledTimerWithTimeInterval but failed miserably. Please help me. I was just doing something like that. I have a UILabel that is called timeReamin in my code. It's updated every second until it reaches 0 and then an alert is displayed. I must warn you that since the timer runs on the same thread as your UI, you may experience some jitter. I have not solved that problem yet, but this works for

NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats doesn't invoke the method

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The timer never invokes the method. What am I doing wrong ? This is the code: NSTimer *manualOverlayTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideManual) userInfo:nil repeats:NO]; method: -(void)hideManual thanks 回答1: It was a thread issue. I've fixed with: dispatch_async(dispatch_get_main_queue(), ^{ // Timer here }); 回答2: You don't need an NSTimer for a task of this sort. To hide your view object after a specific period of time on main thread you can use a gcd method dispatch_after dispatch_after

Set an NSTimer to fire once in the future

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How do I set up an NSTimer to fire once in the future (say, 30 seconds). So far, I have only managed to set it so it fires immediately, and then at intervals. 回答1: The method you want to use is: + ( NSTimer *) scheduledTimerWithTimeInterval :( NSTimeInterval ) seconds target :( id ) target selector :( SEL ) aSelector userInfo :( id ) userInfo repeats :( BOOL ) repeats with repeats == NO arguments and seconds == 30 . This will create the timer and schedule it. It will fire only once, in 30 seconds (and not immediately). 回答2: You can

UILabel Not Updating When Returning to UIViewController

匿名 (未验证) 提交于 2019-12-03 08:30:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a simple app that has an NSTimer object in the appDelegate to be accessed by all views. The structure of the app is with a UINavigationController. When I fire the NSTimer object, my UILabel is being updated with the correct countdown function, but when I go back to the rootViewController and back to the countdown timer view, my UILabel is being updated with the current countdown time, but no subsequent updates to the UILabel happen. What am I missing? I have done research on making sure the UILabel object is not nil, that I call the

(Swift) NSTimer Stop when Scrolling [duplicate]

自古美人都是妖i 提交于 2019-12-03 08:29:06
This question already has an answer here : NSTimer stops during scrolling (1 answer) Help me. I tried to make NSTimer with UIScrollView. but NSTimer stop during Scrolling on UIScroll View.. How can I keep work NSTimer during scrolling? vacawama I created a simple project with a scrollView and a label that is updated with an NSTimer . When creating the timer with scheduledTimerWithInterval , the timer does not run when scrolling. The solution is to create the timer with NSTimer:timeInterval:target:selector:userInfo:repeats and then call addTimer on NSRunLoop.mainRunLoop() with mode

How to pause a NSTimer? [duplicate]

空扰寡人 提交于 2019-12-03 08:06:36
This question already has answers here : How can I programmatically pause an NSTimer? (15 answers) I have a game which uses a timer. I want to make it so the user can select a button and it pauses that timer and when they click that button again, it will unpause that timer. I already have code to the timer, just need some help with the pausing the timer and the dual-action button. Code to timer: -(void)timerDelay { mainInt = 36; timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDownDuration) userInfo:nil repeats:YES]; } -(void)countDownDuration { MainInt -

what is the first step in (NSTimer release and invalidate)?

无人久伴 提交于 2019-12-03 07:57:57
Can I send argument with @selector in NSTimer ? If I want to release NSTimer , are the following steps right in dealloc ? [timer invalidate]; [timer release]; [timer release] only needs to be called if you "own" the timer. From Apple's documentation: Because the run loop maintains the timer, from the perspective of memory management there's typically no need to keep a reference to a timer once you’ve scheduled it. Since the timer is passed as an argument when you specify its method as a selector, you can invalidate a repeating timer when appropriate within that method. In many situations,

How to stop/invalidate NStimer

冷暖自知 提交于 2019-12-03 07:26:46
I am using [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(update) userInfo:nil repeats:YES]; I want to stop calling this timer one. viewDidDisappear How can i do that? invalidate? Declare NSTimer *myTimer in .h file. Assign instance as tom said like this myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(update) userInfo:nil repeats:YES]; Stop and Invalidate using this - (void) viewDidDisappear:(BOOL)animated { [myTimer invalidate]; myTimer = nil; } Try this viewController .h NSTimer *timer; viewcontroller.m timer = [NSTimer