nstimer

Swift : Extra Argument in call with scheduledTimerWithTimeInterval

走远了吗. 提交于 2019-12-11 08:02:46
问题 I create a simple WatchApp Metronome. I use NSTimer with .scheduledTimerWithTimeInterval, and I have an error Extra Argument 'selector' in call Thanks for your answers func playBeat() { if(self.State == true) { self.State == false [labelPlayPause.setTitle("Pause")] } else { self.State == true [labelPlayPause.setTitle("Play")] } BPMValue = 10 var BPMInt:Int = Int(BPMValue) let value = "\(BPMInt) BPM" labelBPM.setText(value) let aSelector: Selector = "playBeat" dispatch_async(dispatch_get_main

Check if NSTimer selector has finished working

人走茶凉 提交于 2019-12-11 07:47:54
问题 I am calling a service method in NSTimer after every 3 seconds. However before each time that method is being called, I want to check if previous one in timer is complete or not. I have done following which is not resulting in success. timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(CallParseOperation) userInfo:nil repeats:YES]; CheckOperation : -(void)CheckOperation{ if([Data getInstance].kOperation == TRUE) { [self CallParseOperation]; } } CallParseOperation

How to stop NSTimer at a specific point?

我的未来我决定 提交于 2019-12-11 07:24:58
问题 I've created a simple button game that gives the user a point with every tap of the button. The button randomly appears on screen every 1.5 seconds. I want the game to end after 30 seconds or after 20 random button pop ups. I've been using the code below to have the button randomly pop-up on the screen: timer = [NSTimer scheduledTimerWithTimeInterval: 1.5 target:self selector:@selector(moveButton:) userInfo:nil repeats:YES]; I've declared the timer in the header file: NSTimer *timer;

Is it possible to save the state of a timer in the User Defaults?

此生再无相见时 提交于 2019-12-11 07:06:49
问题 I have a label on which I am showing countdown timer. Now if I close my app the timer will be off and the label's text also. I know that we can save the label's text value. But how do we show the correct countdown when the app starts again. Suppose I close at 00:05:35 after 3 minutes when app is launched again the label should show 00:02:35 and the timer should be there for remaining countdown 回答1: Yes, simply store the time at which your app was closed and the time left to count down in

Why does my time UILabels skip 2 seconds when it resumes play from a pause state?

╄→尐↘猪︶ㄣ 提交于 2019-12-11 05:55:31
问题 I'm having a weird issue using MPMoviePlayerController . I have a currentTimeLabel representing the current playback time and an endTimeLabel representing the remaining playback time. The function to update the labels is fired off every 1 second using an NSTimer . This coincides with a UISlider that increments every second as the video plays. However, the problem is, as the video is playing, and I tap the Pause button, when I tap the play button again, my currentTimeLabel and endTimeLabel

Implementing “user stopped speaking” notification for `SFSpeechRecognizer`

妖精的绣舞 提交于 2019-12-11 05:51:26
问题 I'm attempting to solve this problem: SFSpeechRecognizer - detect end of utterance The problem is that SFSpeechRecognizer callback fires every time the detected speech string changes, but it only fires after 60 seconds of silence (whereupon it sets the isFinal flag). The suggested technique is to start a 2 second timer each time to callback fires, first invalidating the timer if it is already set. I have implemented this technique. However at my timer callback is never getting hit. Can anyone

iOS sending parameter to selector using NSTimers

拈花ヽ惹草 提交于 2019-12-11 04:33:37
问题 Is there a way to send a parameter to the selector via a NSTimer ? myTimer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:) userInfo:nil repeats:NO]; - (void)removeTheNote:(NSString*)note { NSLog(@"Note %@ ----------- REMOVED!",note); } I know that using : myTimer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:myNote) userInfo:nil repeats:NO]; doesn't work, so I am asking, is there a way to do this? 回答1: You can

How to add 5 seconds to a timer

旧街凉风 提交于 2019-12-11 03:57:01
问题 I'm trying to make a timer showing the following - hours : minutes : seconds : milliseconds. Here is my code: var timer = NSTimer() var startTime = NSTimeInterval() func updateTime() { var currentTime = NSDate.timeIntervalSinceReferenceDate() var elapsedTime : NSTimeInterval = currentTime - startTime let hours = UInt8(elapsedTime / 3600.0) elapsedTime -= (NSTimeInterval(hours) * 3600) let minutes = UInt8(elapsedTime / 60.0) elapsedTime -= (NSTimeInterval(minutes) * 60) let seconds = UInt8

Using NSImageView to display multiple images in quick sucession

时光怂恿深爱的人放手 提交于 2019-12-11 03:18:23
问题 I have an application where, in one window, there is an NSImageView. The user should be able to drag and drop ANY FILE/FOLDER (not only images) into the image view, so I subclassed NSImageView class to add support for those types. The reason why I chose an NSImageView instead of a normal view is because I also wanted to display an animation (say an arrow pointing downwards and going up and down) when the user hovers over with files ready to drop. My question is this: what would be the best

Cannot convert (Timer!) -> Void to ((CFRunLoopTimer?) ->Void)! - Converting NSTimer extension to Swift 3

跟風遠走 提交于 2019-12-11 02:26:31
问题 I am trying to convert a Pod I am using in my project to Swift 3. I didn't write it, but the original author has not updated it so I forked it any I'm trying to do it myself. But... I get this error trying to convert an extension to NSTimer to Swift 3: Cannot convert value of type '(Timer!) -> Void' to expected argument type '((CFRunLoopTimer?) -> Void)! It seems that the Swift 3 handler type, (Timer!) -> Void is not compatible with the old school CFRunLoop style handlers, but I am not sure