nstimer

Swift Memory Issues when using UIView Animation on a Timer

时光总嘲笑我的痴心妄想 提交于 2020-01-03 04:45:09
问题 I'm coding with Swift in Xcode 6.1 and trying to create a simple automatic photo slideshow with a cross-dissolve effect between photos. I figured the best implementation would be to create a scheduled NSTimer that repeats and calls a selector method @IBOutlet var backgroundImageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() backgroundImageView.image = UIImage(named: "1.jpg") let backgroundImageTimer = NSTimer.scheduledTimerWithTimeInterval( 5.0, target: self, selector:

Location update in background and suspended app modes

喜夏-厌秋 提交于 2020-01-03 03:26:13
问题 I want to write application that every 5 min sends to server low-accuracy-location for its both modes: foreground and background. Because I don't want to reduce the battery charge and the locationSignificantChange gives only the high-accuracy-values, I start/stop locationUpdates from GPS every 5 min. Application works fine from foreground mode, but works only about 1 hour from background mode (and stops to send location afterwards). I guess I am missing something in backgroundTask/NSTimer

NSRunLoop freezes with NSTimer and any input

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 02:30:06
问题 For some reason when I push down (click and hold) on any control, the NSTimer in my App freezes and does not fire until I release the mouse button. It simply does not fire while I have the mouse pressed. This is fine for short periods, but it also freezes if I have a popup menu open, or a combobox dropped down. I'm not sure if there is something I missed, but it seems like this is incorrect behavior. I want to be able to click the down arrow of an NSPopUpButtonCell (or even click and hold an

NSTimer with multiple time intervals in a sequence

自闭症网瘾萝莉.ら 提交于 2020-01-02 04:36:06
问题 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. 回答1: 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

How to change the NSTimeInterval of an NSTimer after X seconds?

核能气质少年 提交于 2019-12-31 05:10:19
问题 I'm making an app in swift 2 where there is two timers. After 10 seconds I would like another timer to go faster. I have tried doing it like this but it didn't work (I'm trying to change the var time to 1): @IBOutlet var displayTimeLabel: UILabel! var startTimer = NSTimeInterval() var timer = NSTimer() var timer2:NSTimer = NSTimer() var time = 2.0 @IBAction func Start(sender: UIButton) { if !timer2.valid { timer2 = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector:

Threaded NSTimer

这一生的挚爱 提交于 2019-12-31 04:25:06
问题 I am aware of the many questions regarding this topic, as I myself have asked one previously however, my issue now seems to be more related to the threading part. I have the following 2 methods. -(void) restartTimer { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; self.timer = [NSTimer scheduledTimerWithTimeInterval:1. target:self selector:@selector(dim) userInfo:nil repeats:YES]; time = 31; NSLog(@"calling restart timer"); [self performSelectorOnMainThread:@selector

Checking if NSTimer was added to NSRunLoop

こ雲淡風輕ζ 提交于 2019-12-31 02:59:08
问题 Let's say I'm creating NSTimer in some place in the code and later, I want to add it to the mainRunLoop only if it wasn't already added before: NSTimer* myTimer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(targetMethod:) userInfo:nil repeats:YES]; Another place in the code: if("my myTimer wasn't added to the mainRunLoop") { NSRunLoop *runLoop = [NSRunLoop mainRunLoop]; [runLoop addTimer:myTimer forMode:NSDefaultRunLoopMode]; } Is there a way to check this? 回答1: Try

Analog clock with UIImages for hands?

笑着哭i 提交于 2019-12-30 05:12:27
问题 I want to know how to make an analog clock in iPhone SDK. However, I want the hands of the clock to be custom images and not squares drawn over like in this tutorial: http://iphone-dev-tips.alterplay.com/2010/03/analog-clock-using-quartz-core.html The problem with that tutorial is that the clock hands are drawn with Quarzt Core. I'm okay with that as long as the hands could be custom. What would be the easiest way to make an Analog Clock this way? 回答1: Do it with CALayers. is WAY much easier

[iOS Animation]-CALayer 定时器动画

雨燕双飞 提交于 2019-12-29 22:25:10
定时器的动画 我可以指导你,但是你必须按照我说的做。 -- 骇客帝国 在第10章“缓冲”中,我们研究了 CAMediaTimingFunction ,它是一个通过控制动画缓冲来模拟物理效果例如加速或者减速来增强现实感的东西,那么如果想更加真实地模拟物理交互或者实时根据用户输入修改动画改怎么办呢?在这一章中,我们将继续探索一种能够允许我们精确地控制一帧一帧展示的基于定时器的动画。 定时帧 动画看起来是用来显示一段连续的运动过程,但实际上当在固定位置上展示像素的时候并不能做到这一点。一般来说这种显示都无法做到连续的移动,能做的仅仅是足够快地展示一系列静态图片,只是看起来像是做了运动。 我们之前提到过iOS按照每秒60次刷新屏幕,然后 CAAnimation 计算出需要展示的新的帧,然后在每次屏幕更新的时候同步绘制上去, CAAnimation 最机智的地方在于每次刷新需要展示的时候去计算插值和缓冲。 在第10章中,我们解决了如何自定义缓冲函数,然后根据需要展示的帧的数组来告诉 CAKeyframeAnimation 的实例如何去绘制。所有的Core Animation实际上都是按照一定的序列来显示这些帧,那么我们可以自己做到这些么? NSTimer 实际上,我们在第三章“图层几何学”中已经做过类似的东西,就是时钟那个例子,我们用了 NSTimer 来对钟表的指针做定时动画

定时帧(基于定时器的动画 11.1)

我只是一个虾纸丫 提交于 2019-12-29 22:24:24
定时帧 动画看起来是用来显示一段连续的运动过程,但实际上当在固定位置上展示像素的时候并不能做到这一点。一般来说这种显示都无法做到连续的移动,能做的仅仅是足够快地展示一系列静态图片,只是看起来像是做了运动。 我们之前提到过iOS按照每秒60次刷新屏幕,然后 CAAnimation 计算出需要展示的新的帧,然后在每次屏幕更新的时候同步绘制上去, CAAnimation 最机智的地方在于每次刷新需要展示的时候去计算插值和缓冲。 在第10章中,我们解决了如何自定义缓冲函数,然后根据需要展示的帧的数组来告诉 CAKeyframeAnimation 的实例如何去绘制。所有的Core Animation实际上都是按照一定的序列来显示这些帧,那么我们可以自己做到这些么? NSTimer 实际上,我们在第三章“图层几何学”中已经做过类似的东西,就是时钟那个例子,我们用了 NSTimer 来对钟表的指针做定时动画,一秒钟更新一次,但是如果我们把频率调整成一秒钟更新60次的话,原理是完全相同的。 我们来试着用 NSTimer 来修改第十章中弹性球的例子。由于现在我们在定时器启动之后连续计算动画帧,我们需要在类中添加一些额外的属性来存储动画的 fromValue , toValue , duration 和当前的 timeOffset (见清单11.1)。 清单11.1 使用 NSTimer