nstimer

NSTimer not stopping when invalidated in this function

半腔热情 提交于 2019-12-07 22:26:14
问题 I'm trying to use NTTimer but it doesn't work. It is started here: timer = NSTimer.scheduledTimerWithTimeInterval(0.003, target: self, selector: "openFrameAnimation", userInfo: nil, repeats: true) It fires this function: func openFrameAnimation(){ Swift.print("Animation Goes... ",NSDate().timeIntervalSince1970) self.frame = NSRect(x: self.frame.origin.x, y: self.frame.origin.y-12, width: self.frame.width, height: self.frame.height + 12) if(self.frame.height >= self.finalFrame.height){ Swift

How can I use NSTimer with this simple while loop?

好久不见. 提交于 2019-12-07 21:41:57
问题 I have a -(void) method being executed and at one point it gets to a while loop that gets values from the accelerometer directly the moment it asks for them I went throughout the documentation regarding the NSTimer class but I couldn't make sense of how exactly I am to use this object in my case : e.g. -(void) play { ...... ... if(accelerationOnYaxis >0 && accelerationOnYaxis < 0.9 ) { startTimer; } while(accelerationOnYaxis >0 && accelerationOnYaxis < 0.9) { if(checkTimer >= 300msec) {

Keeping a timer running on another page when navigating around

江枫思渺然 提交于 2019-12-07 18:54:56
问题 I'm trying to keep a timer running on another page when you switch to other pages and complete other tasks, in essence keeping a clock on how long it takes to do the tasks. Whenever I switch to another page, it resets the timer back to what it was started, and does the same with some switches on other pages that I'm trying to keep on. Any ideas? Screenshot of storyboards: Code so far: // // ViewController.m #import "ViewController.h" @interface ViewController () @end @implementation

Proper way of passing a primitive argument with an NSTimer

自闭症网瘾萝莉.ら 提交于 2019-12-07 18:26:13
问题 I'm using a basic timer that calls this method: - (void) refresh:(id)obj { if (obj == YES) doSomething; } I want to call this method from certain areas of my code and also from a timer [NSTimer scheduledTimerWithTimeInterval:refreshInterval target:self selector:@selector(refresh:) userInfo:nil repeats:YES]; When I put YES as the argument for the userInfo parameter, I get an EXC_BAD_ACCESS error; why is this? Can someone help me do this the right way so that there is no ugly casting and such?

Disable a Button for 90 sec when pressed in swift

烈酒焚心 提交于 2019-12-07 16:49:01
问题 I have button that show up a modal view but i want that if the user click it he wont be able to use it again for 90 seconds. how can i do this? 回答1: In the IBAction of the button disable the button and set a timer like this: self.button.enabled = false NSTimer.scheduledTimerWithTimeInterval(90, target: self, selector: "enableButton", userInfo: nil, repeats: false) And create the func called when the timer ends counting: func enableButton() { self.button.enabled = true } 回答2: #Swift 3 Write

Why is NSTimer blocked while another thread is running?

≡放荡痞女 提交于 2019-12-07 16:48:18
问题 I'm trying to run a lenghty task in the background on the iPhone. I start it with performSelectorInBackground . I also create a NSTimer on the main thread just to check if things are working. I expected that the timer would run while the other thread does it's thing: - (void)viewDidLoad { [super viewDidLoad]; [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(onTimerEvent:) userInfo:nil repeats:YES]; [self performSelectorInBackground:@selector(lengthyMethod) withObject

OS X Cocoa timer not fired when application on background

…衆ロ難τιáo~ 提交于 2019-12-07 14:32:56
问题 A third-party library provides a function I need to call every 100ms. Setting up a timer to do that works very well as long as my app is on foreground. When my app is on background timer works for a while but after a about a minute timer is called only after 10 second delay. The same happened when I created a separate thread with usleep-function. Is there any way I can keep timer running while my app is on background? 回答1: Use beginActivityWithOptions:reason: to disable app nap for your

Running NSTimer on a thread

孤者浪人 提交于 2019-12-07 12:38:58
问题 I am trying to run a NSTimer on a thread using iPhone SDK 3.0. I think I am doing everything correctly (new runloop etc.). If I call [timer invalidate] on viewDidDissappear though I get this error: bool _WebTryThreadLock(bool), 0x3986d60: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now... Program received signal: “EXC_BAD_ACCESS”. Here is my code: - (void)viewDidAppear:(BOOL

How to create a timer in Spritekit?

邮差的信 提交于 2019-12-07 11:07:00
问题 Ive figured out how to make a timer in a single-view application, but not Spritekit. When I use the following code, I get 2 errors(listed below). Can anyone help me out with this? Thanks, Jack. The timer. if(!_scorelabel) { _scorelabel = [SKLabelNode labelNodeWithFontNamed:@"Courier-Bold"]; _scorelabel.fontSize = 200; _scorelabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)); _scorelabel.fontColor = [SKColor colorWithHue: 0 saturation: 0 brightness: 1 alpha: .5]

NSTimer for UITableviewcell similar to World Clock app

久未见 提交于 2019-12-07 06:40:18
问题 I would like to build a few simple countdown timers in a UITableview. I noticed the World Clock app has animated clocks in each of it's rows. What is the best method to firing an NSTimer to update each table row? Can a single timer be run that updates all cells or should I have a custom view subclass with built in timer that is added to each row? I am just trying to get a proper course of action. 回答1: One timer is sufficient. When it fires, ask the table view for the visible cells and update