nstimer

NSTimer not working while dragging a UITableView

我的梦境 提交于 2019-12-18 03:14:23
问题 I have an application with a countdown timer. I've made it with a label that is updated with a function called from a timer this way: ... int timeCount = 300; // Time in seconds ... NSTimer *myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(actualizarTiempo:) userInfo:nil repeats:YES]; ... - (void)actualizaTiempo:(NSTimer *)timer { timeCount -= 1; if (timeCount <= 0) { [timer invalidate]; } else { [labelTime setText:[self formatTime:timeCount]]; } } Note:

Prevent NSTimer firing delays in background app

自闭症网瘾萝莉.ら 提交于 2019-12-17 20:32:52
问题 I'm working on a macOS app (let's call it the "display app") that displays a clock and other data, which is controlled by another app (the "control app") on the same machine via a TCP connection. I have noticed that when the display app is idle for some time (> 60 sec.) and then schedules an NSTimer (with a .2 second interval), it takes a very long time before the timer fires for the first time (in the range of 6-10 seconds, sometimes longer.) That happens mostly when the display app is not

swift invalidate timer doesn't work

眉间皱痕 提交于 2019-12-17 20:05:03
问题 I have this problem for a few days now and I don't get what I am doing wrong. My application is basically just creating some timers. I need to stop them and create new ones. But at the moment stopping them doesn't work. self.timer = NSTimer.scheduledTimerWithTimeInterval(timeInterval, target:self, selector: "timerDidEnd:", userInfo: "Notification fired", repeats: false) That's my timer func timerDidEnd(timer:NSTimer){ createUnrepeatedAlarmWithUpdateInterval() } Because my timer didn't want to

How can I pause and resume NSTimer.scheduledTimerWithTimeInterval in swift?

南楼画角 提交于 2019-12-17 19:32:45
问题 I'm developing a game and I want to create a pause menu. Here is my code: self.view?.paused = true but NSTimer.scheduledTimerWithTimeInterval still running... for var i=0; i < rocketCount; i++ { var a: NSTimeInterval = 1 ii += a delaysShow = 2.0 + ((stimulus + interStimulus) * ii) var time3 = NSTimer.scheduledTimerWithTimeInterval(delaysShow!, target: self, selector: Selector("showRocket:"), userInfo: rocketid[i], repeats: false) } I want time3 to pause the timer when player click pause menu

sound and Nstimer stopped when iphone is in deepsleepmode?

徘徊边缘 提交于 2019-12-17 19:31:31
问题 I am creating an application in which I'm using nstimer and avaudioplayer to play sound,but both sound and timer stops when phone is in deep sleep mode.how to solve this issue? here is the code to play audio -(void)PlayTickTickSound:(NSString*)SoundFileName { //Get the filename of the sound file: NSString *path = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] resourcePath],[NSString stringWithFormat:@"/%@",SoundFileName]];// @"/Tick.mp3"]; //Get a URL for the sound file NSURL

Best time to invalidate NSTimer inside UIViewController to avoid retain cycle

风流意气都作罢 提交于 2019-12-17 17:54:48
问题 Does any one know when is the best time to stop an NSTimer that is held reference inside of a UIViewController to avoid retain cycle between the timer and the controller? Here is the question in more details: I have an NSTimer inside of a UIViewController. During ViewDidLoad of the view controller, I start the timer: statusTimer = [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector(updateStatus) userInfo: nil repeats: YES]; The above causes the timer to hold a

Implementing a Countdown Timer in Objective-c?

我们两清 提交于 2019-12-17 17:34:39
问题 I am new to iOS programming. I am working on words matching game. In this game I need to implement time counter which shows minutes and seconds. I want when my game is started my timer to start with 3 minutes. Now I want to decrease this timer in reverse direction with seconds. my code just work for seconds..here is my code: secondsLeft--; int seconds = (secondsLeft %3600) % 60; Timerlbl.text = [NSString stringWithFormat:@"%02d",seconds]; if (seconds==0) { UIAlertView *pAlert = [[UIAlertView

UIScrollView pauses NSTimer while scrolling

自闭症网瘾萝莉.ら 提交于 2019-12-17 16:33:17
问题 I have a UIScrollView that has a series of labels which are rapidly updating numbers (every .06 seconds). While the scroll view is moving, however, the NSTimer is paused and does not continue until after the scrolling and the elastic animation have finished. How can I avoid this and have the NSTimer run regardless of the state of the scroll view? 回答1: An easy way to fix this is adding your NSTimer to the mainRunLoop . [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; To

Using an NSTimer in Swift

北战南征 提交于 2019-12-17 15:43:01
问题 In this scenario, timerFunc() is never called. What am I missing? class AppDelegate: NSObject, NSApplicationDelegate { var myTimer: NSTimer? = nil func timerFunc() { println("timerFunc()") } func applicationDidFinishLaunching(aNotification: NSNotification?) { myTimer = NSTimer(timeInterval: 5.0, target: self, selector:"timerFunc", userInfo: nil, repeats: true) } } 回答1: You can create a scheduled timer which automatically adds itself to the runloop and starts firing: Swift 2 NSTimer

NSTimer - how to delay in Swift

ε祈祈猫儿з 提交于 2019-12-17 15:28:37
问题 I have a problem with delaying computer's move in a game. I've found some solutions but they don't work in my case, e.g. var delay = NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: nil, userInfo: nil, repeats: false) I tried to use this with function fire but also to no effects. What other possibilities there are? 回答1: Swift 3 With GCD: let delayInSeconds = 4.0 DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delayInSeconds) { // here code perfomed with delay }