nstimer

Can't invalidate, stop countdown NSTimer - Objective C

萝らか妹 提交于 2020-01-06 08:23:19
问题 Problem is to stop NSTimer, for some reason [Timer invalidate] just not working... Maybe my eyes are full of soap, but can't understand the reason why the timer didn't stop at 0, but go reverse counting -1, -2, -3 and so on...((( I'm using epoch numbers as destination date. One more thing - my button "IBAction stop" with [Timer invalidate] works just fine - when i push it in simulator timer stops... @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; Timer = [NSTimer

NSTimer problem

一笑奈何 提交于 2020-01-06 06:10:20
问题 In my app I used the code below with a timer of interval equal to 1.0f/30.0f which meant that it is called 30 times per second to call incrementSpeed . I notice in the log file that the value of moduloResult is equal to '0' for a second and incrementSpeed is called 30 times every 5 seconds, but I want it to call it just 1 time for every 5 seconds. - (void)move:(NSTimer *)theTimer { // ... CGFloat moduloResult = (float)((int)time % (int)5); NSLog(@"mod = %f",moduloResult); if (!moduloResult) {

Swift NSTimer retrieving userInfo as CGPoint

☆樱花仙子☆ 提交于 2020-01-06 04:01:11
问题 override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { let touch = touches.anyObject() as UITouch let touchLocation = touch.locationInNode(self) timer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "shoot", userInfo: touchLocation, repeats: true) // error 1 } func shoot() { var touchLocation: CGPoint = timer.userInfo // error 2 println("running") } I am trying to create a timer that runs periodicly that passes the touched point (CGPoint) as userInfo to

Probelem with NSTimer

左心房为你撑大大i 提交于 2020-01-06 03:37:39
问题 I have a problem with a NSTimer . I received a "SIGABRT" error and [NSCFTimer intValue]: unrecognized selector sent to instance These is my code: -(void)detectionMove:(NSNumber*)arrayIndex{ static BOOL notFind = FALSE; static int countVariable = 0; static int countRilevamenti = 0; notFind = FALSE; for(int i = countVariable+1; i<[[[[sharedController arrayMovement]objectAtIndex:[arrayIndex intValue]] arrayPositionMove]count]; i++){ if(!notFind){ if((actualAccelerometerX+sensibilityMovement) >=

IOS, how to handle multiple local notifications when app start?

时光总嘲笑我的痴心妄想 提交于 2020-01-05 05:46:09
问题 I'm creating an app that uses timers. Let's say that the user can set multiple timers; for each of those timers the app schedule a local notification. When the app is running in foreground or is in background i have no problem handling multiple local notifications. my problem is when the user set multiple timers and then terminate the app ( double click on home button and close the app). in that case, when timers expire all relative local notifications are shown as a banner and the app icon

深入理解CADisplayLink和NSTimer

你离开我真会死。 提交于 2020-01-05 04:10:44
一、什么是CADisplayLink 简单地说,它就是一个定时器,每隔几毫秒刷新一次屏幕。 CADisplayLink是一个能让我们以和屏幕刷新率相同的频率将内容画到屏幕上的定时器。我们在应用中创建一个新的 CADisplayLink 对象,把它添加到一个runloop中,并给它提供一个 target 和 selector 在屏幕刷新的时候调用。 一但 CADisplayLink 以特定的模式注册到runloop之后,每当屏幕需要刷新的时候,runloop就会调用CADisplayLink绑定的target上的selector,这时target可以读到 CADisplayLink 的每次调用的时间戳,用来准备下一帧显示需要的数据。例如一个视频应用使用时间戳来计算下一帧要显示的视频数据。在UI做动画的过程中,需要通过时间戳来计算UI对象在动画的下一帧要更新的大小等等。 在添加进runloop的时候我们应该选用高一些的优先级,来保证动画的平滑。可以设想一下,我们在动画的过程中,runloop被添加进来了一个高优先级的任务,那么,下一次的调用就会被暂停转而先去执行高优先级的任务,然后在接着执行CADisplayLink的调用,从而造成动画过程的卡顿,使动画不流畅。 duration属性:提供了每帧之间的时间,也就是屏幕每次刷新之间的的时间

NSTimer理解

半城伤御伤魂 提交于 2020-01-05 04:06:00
NSTimer 其实是将一个监听加入的系统的 RunLoop 中去,当系统 runloop 到如何 timer 条件的循环时,会调用 timer 一次,当 timer 执行完,也就是回调函数执行之后, timer 会再一次的将自己加入到 runloop 中去继续监听。 CFRunLoopTimerRef 和 NSTimer 这两个类型是可以互换的, 当我们在传参数的时候,看到 CFRunLoopTimerRef 可以传 NSTimer 的参数,增加强制转化来避免编译器的警告信息 指定(注册)一个 timer 到 RunLoops 中 一个 timer 对象只能够被注册到一个 runloop 中在同一时间,尽管在这个 runloop 中它能够被添加到多个 runloop 中模式中去。 有以下三种方法: 使用 scheduledTimerWithTimeInterval:invocation:repeats: 或者 scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: 这两个类方法创建一个 timer 并把它指定到一个默认的 runloop 模式中 使用 timerWithTimeInterval:invocation:repeats: 或者 timerWithTimeInterval:target

NSTimer类的使用

我的梦境 提交于 2020-01-05 04:01:53
转载于: http://www.cnblogs.com/wujian1360/archive/2011/09/05/2167992.html 创建一个 Timer + scheduledTimerWithTimeInterval: invocation: repeats: + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti invocation:(NSInvocation *)invocation repeats:(BOOL)yesOrNo; + scheduledTimerWithTimeInterval: target: selector: userInfo: repeats: + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo; 创建返回一个新的 NSTimer 对象和时间表,在当前的默认模式下循环调用一个实例方法。 + timerWithTimeInterval: invocation: repeats: + (NSTimer *

Schedule Tasks to execute methods in iOS

可紊 提交于 2020-01-04 02:56:10
问题 I would like to schedule tasks in iOS to execute a method depending on the time of the day and the day. For example, I want to execute startMonitorRegion every day at 10pm and stopMonitorRegion at 10am. I don't want to send a local notification to alert the user, it needs to be transparent for the user. Is anyway to do it using NSTimer? The app will be in background. 回答1: You can utilize Local notifications for this purpose. Just schedule local notification for some date/time. and once user

Swift Timer() will not update label after switching between views

半世苍凉 提交于 2020-01-03 04:46:08
问题 I have a really basic two-view timer app I'm working on, wherein on View1 I have 30 buttons (15 buttons start timers, 15 of them invalidate each respective timer) and on View2 I have some other functionality not pertinent to my issue. The issue is that my user switches back and forth between these two views while the timers are still running - the timers will still increment as normal when switching between the views but will cease updating their respective labels once they are switched back