nstimer

[iOS Animation]-CALayer 定时器动画演示一

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

NSTimer not firing selector when added with scheduledTimerWithTimeInterval

一曲冷凌霜 提交于 2019-12-10 03:59:39
问题 I have a code snippet like this: m_timer = [NSTimer scheduledTimerWithTimeInterval:timeOutInSeconds target:self selector:@selector(activityIndicatorTimer:) userInfo:nil repeats:NO]; When I call it like so the selector is not fired after the given timeOutInSeconds. However, if I modify it to be like the following, then the selector is called twice. NSLog(@"Timer set"); m_timer = [NSTimer scheduledTimerWithTimeInterval:timeOutInSeconds target:self selector:@selector(activityIndicatorTimer:)

How do I create an accurate timer event in Objective-C/iOS?

孤街醉人 提交于 2019-12-09 18:20:22
问题 I'm looking to create a countdown timer for SMPTE Timecode (HH:MM:SS:FF) on iOS. Basically, it's just a countdown timer with a resolution of 33.33333ms. I'm not so sure NSTimer is accurate enough to be counted on to fire events to create this timer. I would like to fire an event or call a piece of code every time this timer increments/decrements. I'm new to Objective-C so I'm looking for wisdom from the community. Someone has suggested the CADisplayLink class, looking for some expert advice.

what is the first step in (NSTimer release and invalidate)?

不羁岁月 提交于 2019-12-09 06:30:29
问题 Can I send argument with @selector in NSTimer ? If I want to release NSTimer , are the following steps right in dealloc ? [timer invalidate]; [timer release]; 回答1: [timer release] only needs to be called if you "own" the timer. From Apple's documentation: Because the run loop maintains the timer, from the perspective of memory management there's typically no need to keep a reference to a timer once you’ve scheduled it. Since the timer is passed as an argument when you specify its method as a

view controller variables in ApplicationWillResignActive

五迷三道 提交于 2019-12-09 04:52:26
I'm trying to make my timer "run" in the background by saving the time to disk on entering background and retrieving it on entering foreground. Each view controller has a timer and a timeInterval specified by the user. The problem is, I don't know how to access the timeInterval variable. I think I can get the difference of time by using something like this (would this work?): NSTimeInterval idleTime = [dateReturnedToForeground timeIntervalSinceDate:dateEnteredBackground]; NSTimeInterval elapsedTime = [[NSDate date] timeIntervalSinceDate:startDate]; elapsedTime -= idleTime; Each view controller

[__NSCFTimer copyWithZone:]: unrecognized selector sent to instance

天大地大妈咪最大 提交于 2019-12-09 01:54:37
问题 var searchDelayer:NSTimer? func searchBar(searchBar: UISearchBar!, textDidChange searchText: String!) { searchDelayer?.invalidate() searchDelayer = nil searchDelayer = NSTimer.scheduledTimerWithTimeInterval(1.5, target: self, selector: Selector("doDelayedSearch:"), userInfo: searchText, repeats: false) } func doDelayedSearch(text:String){ ... } Why this code crashes with error message: [__NSCFTimer copyWithZone:]: unrecognized selector sent to instance Updated: Terminating app due to uncaught

NSTimer repeating too fast

不羁的心 提交于 2019-12-08 14:39:42
问题 The Problem I am building an app where I am getting real-time data and updating a MKMapView. I get a batch of data every 10 seconds and between data sets from the webs service I am removing older data points while also adding the new ones. Instead of updating them all at once I want spread out the animation of the new points I get from the data service over that 10 seconds so I create the 'real-time' feel and avoid as many stops and starts as I can. Everything seems to be working great except

Why are my audio sounds not playing on time?

你。 提交于 2019-12-08 13:57:48
One of my apps has a simple metronome-style feature that plays a click sound a specified number of times per minute (bpm). I'm doing this by starting an NSTimer, with an interval calculated from the specified bpm, that calls a method that plays the sound. If I put an NSLog line into the play method, I can see that NSTimer is firing accurately to about 1 millisecond. However, if I record the sound output into an audio editor and then measure the interval between clicks, I can see that they are not evenly spaced. For example, with 150 bpm, the timer fires every 400 milliseconds. But most of the

How to give image Animations to multiple images at Different Locations in a UIView?

房东的猫 提交于 2019-12-08 13:09:53
问题 How to give 'image' Animations to multiple images at Different Locations in a 'UIView'? 1) I had 3 images. 2) i want to Add these 3 Images at 3 different locations animatedly, means add one by one images animatedly with some duration ?? How can I achieve this? 回答1: As per your requirement you want to animate image one by one for that purpose use completion block of first image animation to animate second image and so on like below code UIImageView *imgView = [[UIImageView alloc] initWithImage

What is the best way (performance-wise) to flash things at a varying speed?

我与影子孤独终老i 提交于 2019-12-08 11:52:24
问题 I have an app where I flash words at a constant speed. Say it's set to 60 times a minute. Each word then shows for 1 second each. It was pretty easy to accomplish with NSTimer . However, I want to make it a little more intelligent now. Longer words show for slightly longer than shorter words. I've figured out the math on how to calculate this, but I'm not sure how in Objective-C to present a word for say, 0.15 seconds, then another word for 0.18 seconds, then a third word for 0.04 seconds,