nstimer

NSTimer Too Slow

南笙酒味 提交于 2019-11-28 12:59:13
问题 I have seen multiple questions similar to this; however, none of them resolved my problem. My timer is simply going too slowly. I am only using an interval of 0.01 seconds. Here is my code: @IBOutlet var timerLabel: UILabel! var miliseconds = 0 var seconds = 0 func updateLabel() { if miliseconds == 0 { timerLabel.text = "\(seconds).00" } else if miliseconds < 10 { timerLabel.text = "\(seconds).0\(miliseconds)" } else { timerLabel.text = "\(seconds).\(miliseconds)" } } var timer = NSTimer()

Question about NSTimer and retain

限于喜欢 提交于 2019-11-28 12:40:02
问题 This code works well @property (nonatomic, retain) NSTimer *timer; self.timer = [[NSTimer timerWithTimeInterval:kAdsAppearTimeInterval target:self selector:@selector(timerFired:) userInfo:nil repeats:NO] retain]; this code get CFRelease . But why? i use retain property self.timer = [NSTimer timerWithTimeInterval:kAdsAppearTimeInterval target:self selector:@selector(timerFired:) userInfo:nil repeats:NO]; 回答1: Not a lot to go on... but: @property (nonatomic, retain) NSTimer *timer; self.timer =

Xcode / Objective-C: Why is NSTimer sometimes slow/choppy?

帅比萌擦擦* 提交于 2019-11-28 11:36:42
I am developing an iPhone game and I have an NSTimer that animates all of the objects on the screen: EverythingTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self selector:@selector(moveEverything) userInfo:nil repeats:YES]; Most of the time it runs very smoothly, but sometimes I see things move slower or choppy. I have pause and resume functions that stop and start the timers respectively. When I pause then unpause, it seems to fix the choppiness. Any ideas to why this is happening? or How can i fix it? Any ideas to why this is happening? The short answer is that in your case

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

我们两清 提交于 2019-11-28 10:47:10
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 and continue run the timer when player come back to the game, but how can I pause NSTimer

sound and Nstimer stopped when iphone is in deepsleepmode?

安稳与你 提交于 2019-11-28 10:37:21
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 *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; NSError *error; if(self.TickPlayer==nil) { self

Objective-C : NSTimer and countdown

99封情书 提交于 2019-11-28 09:29:53
I know that I should understand Apple's documentation for NSTimer, but I don't! I have also read a lot of questions about it but can not find one that suites my case. Well here it is: The user enter hour and minutes through textfields. I convert those to integers and display them in a "countDownLabel". How can i make the count down to zero? It would be nice to show the seconds which is something that the user didn't imported but i guess it will not be hard to show. How could somebody stop this procedure with a press of a UIButton? I know that i am asking a lot...I would be really grateful if

Schedule multiple, daily events with NSTimer?

限于喜欢 提交于 2019-11-28 06:33:57
问题 I have a schedule cache stored in an NSDictionary . For the example below, I have a schedule time of January 13, 20120 2:00PM and January 13, 2012 2:05PM . How can I add both of these to a queue to fire on their own? Build the Schedule Cache: -(void) buildScheduleCache { NSCalendarDate *now = [NSCalendarDate calendarDate]; NSFileManager *manager = [[NSFileManager defaultManager] autorelease]; path = @"/var/mobile/Library/MobileProfiles/Custom Profiles"; theProfiles = [manager

How to pass arguments when calling function with timer in objective c

↘锁芯ラ 提交于 2019-11-28 06:01:10
问题 -(void)setX:(int)x andY:(int)y andObject:(Sprite*)obj { [obj setPosition:CGPointMake(x,y)]; } Now, I want to call above method, using following timer. [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector() userInfo:nil repeats:NO]; What to set Here? How to Pass arguments? (as per my knowledge - selector specifies only the method to invoke) 回答1: You'll need to used +[NSTimer scheduledTimerWithTimeInterval:invocation:repeats:] instead. By default, the selector used to fire a

Best time to invalidate NSTimer inside UIViewController to avoid retain cycle

為{幸葍}努か 提交于 2019-11-28 05:46:05
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 reference to the view controller. Now I want to release my controller (parent controller releases it for

applicationDidEnterBackground and applicationWillEnterForeground method are not called when pressed home button in iOS simulator

这一生的挚爱 提交于 2019-11-28 05:32:15
问题 I need a long running task to be done in background as well as in foreground. This updates the core data. So to maintain UI responsive I created an another thread where I use different managedObjectContext(MOC). So a timer is set in background as well as in foreground and is inactivated appropriately when state changes. Before the task is starting and after the task is completed when I press home button it calls the two delegate methods properly but during the task is active when I press home