nstimer

Stopwatch counting in powers of 2

ぐ巨炮叔叔 提交于 2019-12-11 02:11:40
问题 I am making a stopwatch in Objective-C: - (void)stopwatch { NSInteger hourInt = [hourLabel.text intValue]; NSInteger minuteInt = [minuteLabel.text intValue]; NSInteger secondInt = [secondLabel.text intValue]; if (secondInt == 59) { secondInt = 0; if (minuteInt == 59) { minuteInt = 0; if (hourInt == 23) { hourInt = 0; } else { hourInt += 1; } } else { minuteInt += 1; } } else { secondInt += 1; } NSString *hourString = [NSString stringWithFormat:@"%d", hourInt]; NSString *minuteString =

passing a block in @selector()

a 夏天 提交于 2019-12-11 01:42:36
问题 How do I pass a block, and what would it look like, in the method incrementCount:completion to get the property self.count returned after its increment in the CounterClass? I'm not sure if the way I defined the block parameter (void(^)(void))callback; in the method is correct i.e. should it also have a return value? ViewController [NSTimer scheduledTimerWithTimeInterval:3.0 target:self.counterClass selector:@selector(incrementCount:completion:) userInfo:nil repeats:YES]; CounterClass -(void

how to keep running NSTimer when app goes in background

拈花ヽ惹草 提交于 2019-12-11 01:14:02
问题 I am creating puzzle game application and in that I am displaying time (i.e 01:20) using NSTimer. NSTimer is paused when application gone in background but i want to continue it even application is in background state. for example timer count is 15 sec when app gone in background and I put it for 5 sec and become in foreground now I need to timer count changes to 20 sec I have searched a lot but didn't get good answer. So Please suggest me how can I achieve this. 回答1: Don't think of a timer

Swift cannot output when using NSTimer

北城以北 提交于 2019-12-11 00:43:30
问题 I tried output to STDOUT every second by using NSTimer . I wrote the following code and saved it as sample.swift. #!/usr/bin/swift import AppKit class Foo : NSObject { override init() { super.init() NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "bar", userInfo: nil, repeats: true) } func bar() { print("buz") } } let h = Foo() // Output successful // while true { // print("Foo!") // } NSRunLoop.mainRunLoop().run() Then, I executed the following command and can see buz .

NSTimer not repeating from AppDelegate

…衆ロ難τιáo~ 提交于 2019-12-10 23:53:08
问题 why would this not repeat when place in appDidFinishLaunching? self.ti = [NSTimer timerWithTimeInterval:10. target:self selector:@selector(bounce:) userInfo:nil repeats:YES]; [self.ti fire]; many thanks Jules 回答1: I think your bounce has a wrong signature. It should be - (void)bounce:(NSTimer*)theTimer { NSLog(@"Here..."); } You should be using selector(bounce:) to schedule this method. You should also be calling scheduledTimerWithTimeInterval instead of timerWithTimeInterval : self.ti =

Any way to speed up gameplay gradually in Swift?

爱⌒轻易说出口 提交于 2019-12-10 21:17:12
问题 I'm currently working on a game using Spritekit. The game has objects which spawn at the top of the screen and fall towards the player character, and the game ends when the player character collides with any of the objects. I am trying to find a way to gradually speed up gameplay over time to make the game more difficult (i.e. objects fall at normal speed when the game begins, after 5 seconds speed up 50%, after 5 more seconds speed up another 50%, ad infinitum.) Would I need to use NSTimer

AVPlayerStatus vs AVPlayerItemStatus

99封情书 提交于 2019-12-10 14:09:06
问题 The issue is that player.status returns AVPlayerStatusReadyToPlay a full 2 seconds before player.currentItem.status returns AVPlayerItemStatusReadyToPlay . Does anyone have any helpful explanations as to why this is happening? This is just sample code to show the basic idea of what's happening so if there are any typos or whatever please ignore them. - (void) someMethod { player = [[AVPlayer alloc] initWithURL:someValidURL]; [player play]; NSTimer *timer = [NSTimer timerWithTimeInterval:0.1

how to resume timer when poping to view2

旧时模样 提交于 2019-12-10 12:27:08
问题 my application has 3 views in view1 only one button (play level 1) that pushes to veiw2 and updates titlelabel in view2 when view2 loads and appears a timer starts to count down and update another label in view2 itself, also view2 has button that pauses the timer and pushes to view3 in view3 only one button that pop back to view2 and resumes thee timer my problem is that when i pop from view3 to view2 the timer is still paused any help please? Thanks & kind regards. view1.h #import <UIKit

Pause NSTimer on home-button-press and start them again once the app is in foreground

左心房为你撑大大i 提交于 2019-12-10 11:26:06
问题 I've been searching for a solution to pause my SpriteKit game when the user "tabs down" the game. So far I found a solution where you use SKAction 's instead of NSTimer 's, this works as long as the time between actions stays the same. However, my NSTimer 's changes in speed. So I need to find another solution. I have a bunch of NSTimer 's located in GameScene -> didMoveToView NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: Selector("SpawnBullets"), userInfo: nil, repeats:

Display StopWatch Timer animated like the petrol pump meter using NSTimer

落爺英雄遲暮 提交于 2019-12-10 10:17:23
问题 I am new in iOS developement.When I press the stopwatch start button I want to display the timer like counter token effect.I have attached image for your reference.I have done to display secs and minutes but I dont know, How animate autoscroll effect? How can I do this? When the counter is moving it shouldn't jump from one number to another number, instead it should move from one number to next number smoothly, just like the petrol pump meter. Thanks 回答1: You need to manually scroll tableView