nstimer

Animation stops when scrolling in UIScrollView

匆匆过客 提交于 2019-12-05 16:07:10
So I am trying to make a game where the user must scroll down as fast as they can in order to escape a "block" that grows infinitely bigger. Here is my problem: I am using a UI ScrollView as my mechanism for scrolling with a normal UI View as a subview. I have a time set to fire every 0.005 seconds that increases the height of both the "block" and the content height of the scroll view (so that the user can technically scroll infinitely). The problem is that whenever the user begins to scroll, this stops firing (i.e. the block stops getting taller). However, immediately when the user stops

NSTimer 的官方推荐替代 MSWeakTimer 分析

不羁的心 提交于 2019-12-05 15:35:53
基本介绍 线程安全的MSWeakTimer是NSTimer的替代品,最基本的特点是它不会 retain target 以及支持GCD queues。 问题的提出 关于 NSTimer 中 target 的生命周期问题, 啸笑天 同学在他的 博客 中说的很清楚了。 当 repeat 为 YES 时 NSTimer 会 retains 它的 target,那么target的生命周期就成了问题,完全的交给了这个timer,只有 当timer 调用invalidate后 dealloc 才有机会发生 。 另一个问题是GCD,在苹果的官方文档 中说的很清楚: Special Considerations You must send this message from the thread on which the timer was installed. If you send this message from another thread, the input source associated with the timer may not be removed from its run loop, which could prevent the thread from exiting properly. invalidate必须由安装这个timer的线程发起

How to check if NSTimer has been already invalidated

有些话、适合烂在心里 提交于 2019-12-05 15:10:37
问题 I have a NSTimer object that I need to invalidate if a user taps on a button or if they exit a view. So I have: [myNSTimer invalidate]; inside my button handler and inside viewWillDisappear . If user taps on a button and then exists a view the app throws an exception because myNSTimer has already been invalidated. What I need to do in the viewWillDisappear method is check if the myNSTimer has been invalidated or not. How do I do that? I've tried: if(myNSTimer != nil) [myNSTimer invalidate];

How to create a timer in Spritekit?

六眼飞鱼酱① 提交于 2019-12-05 12:35:22
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]; [self addChild:_scorelabel]; } _scorelabel = [NSTimer scheduledTimerWithTimeInterval: 1 target:self

NSTimer with multiple time intervals in a sequence

时光怂恿深爱的人放手 提交于 2019-12-05 10:55:53
Without creating multiple NSTimer instances, how would one achieve an NSTimer to fire a specific or multiple method with different intervals in a sequence. For example method1 (0.3 sec), method2 (0.5), method3 (0.7) and so on. I would appreciate if someone could please share any example code. holex I'm not sure what your final goal is with this but after reading your question I would recommend to try the following way , maybe this is what you'd look for. you should put this code where you normally wanted to start the same NSTimer class with different intervals (what is not possible,

NSTimer for UITableviewcell similar to World Clock app

不想你离开。 提交于 2019-12-05 10:40:58
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. One timer is sufficient. When it fires, ask the table view for the visible cells and update them one by one. You could also just call reloadData when the timer fires but depending on how you draw your

Trivial “+[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector” error

£可爱£侵袭症+ 提交于 2019-12-05 10:37:34
I am banging my head against an odd error after a move to 10.12/Sierra and Xcode 8.1: +[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector sent to class 0x7fff78f1fa88 The most minimal code (default settings of create a new project) to reproduce this is: // AppDelegate.m // #import "AppDelegate.h" @interface AppDelegate () @property (weak) IBOutlet NSWindow *window; @property (strong, nonatomic) NSTimer * timer; @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.timer = [NSTimer scheduledTimerWithTimeInterval

multiple countdown timers inside uitableview

蹲街弑〆低调 提交于 2019-12-05 10:18:50
How do I go about this task? Basically, I will have an array of "seconds int" listed inside the UITableView. So how can I assign each "seconds int" to countdown to zero? The possible problems I'm seeing is the timers not being updated when the cell is not yet created. And how do I instantiate multiple independent NSTimers updating different ui elements? I'm quite lost here, so any suggestions is greatly appreciated. for visual purposes, I want to have something like this: From the image, it looks like your model is a set of actions the user plans to take. I would arrange things this way: 1)

Set timer to UIPageViewController

筅森魡賤 提交于 2019-12-05 07:29:02
问题 I'm trying to have the UIPageViewController navigate through the pages for every 5 seconds. How to do this in Swift? Is there any way to explicitly call viewControllerAfterViewController ? var timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("update"), userInfo: nil, repeats: true) func update() -> UIViewController { // can u please tell me what to add here } func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController

Keep an NSThread containing an NSTimer around indefinitely? (iPhone)

跟風遠走 提交于 2019-12-05 07:24:10
问题 I have some web service data in my app that needs to be updated every 3 minutes. I had tried out a few approaches but got a really good piece of advise in here last week, I should not build a new thread every 3 minutes and then subsequently try and dealloc and synchronize all the different parts so that I avoided memory bug. Instead I should have a "worker thread" that was always running, but only did actual work when I asked it too (every 3 minutes). As my small POC works now, I spawn a new