Tag: 定时器

在swift中保存variables和布尔值3

我是iOS开发新手,目前正在创build我的第一个应用程序,其核心function是一个计时器 我有几个不同的variables(例如计时器的开始时间)和定时器是否运行的布尔值。 有没有办法可以保存计时器的开始时间或布尔值,即使应用程序closures? 我使用NSDate来存储开始时间,并将当前时间与此进行比较,以产生一个经过的时间值。 提前致谢!

iPhone数字时钟

经过很长时间,我花了一个模拟时钟工作,我试图做一个数字( 叹气 )。 我正在试图用数字0-9的10个PNG做到这一点。时钟的每个数字都是一个图像。 唯一的问题是从当前时间检索某个数字。 我已经尝试将时间转换为string,并使用characterAtIndex,但似乎并没有工作。 什么是解决这个问题的最好方法?

如何在iOS设备中一秒钟抓取30个截图?

在我的iOS应用程序中,我使用NSTime来调用一个截取设备屏幕截图的方法。 我每秒钟截取30个截图。 在模拟器上工作正常(因为Mac的处理器比iPad强大得多)。 但是在实际设备中占用的屏幕截图数量较less。 我怎样才能做到这一点? 任何可靠的替代计时器? 请帮忙

暂停和重新创build计时器与通知问题Swift

所以我有两个计时器,一个提高分数,一个产生敌人。 我使用通知来使计时器无效,然后我使用另一个来重新创build计时器。 当我退出,然后打开应用程序,有两组敌人彼此顶部产卵。 我认为timerRecreate = true,GameScene中的常规定时器也被调用。 GameViewController.swift文件: class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("pauseTimers:"), name:UIApplicationWillResignActiveNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("startTimers:"), name:UIApplicationDidBecomeActiveNotification, object: nil) } func pauseTimers(notification : NSNotification) { println("Observer method called") timer.invalidate() scoretimer.invalidate() } func startTimers(notification : NSNotification) { println("Observer method called") timerRecreate = true } GameScene.swift中的定时器代码 override func […]

无法转换(定时器!) – >无效(((CFRunLoopTimer?) – >无效)! – 将NSTimer扩展转换为Swift 3

我试图将我在我的项目中使用的Pod转换为Swift 3.我没有写它,但原来的作者没有更新它,所以我分叉它,我试图自己做。 但… 我得到这个错误试图将扩展名转换为NSTimer到Swift 3: Cannot convert value of type '(Timer!) -> Void' to expected argument type '((CFRunLoopTimer?) -> Void)! 看起来,Swift 3处理程序types(Timer!) -> Void与旧的CFRunLoop风格的处理程序不兼容,但我不确定如何在保持与iOS 9的兼容性的同时将其转换。 我粘贴下面的代码,由Xcode转换。 您可以在https://github.com/entotsu/TKSubmitTransition/blob/master/SubmitTransition/Classes/NSTimerEx.swiftfind原始代码 干杯 import Foundation extension Timer { class func schedule(delay delay: TimeInterval, handler: (Timer!) -> Void) -> NSTimer { let fireDate = delay + CFAbsoluteTimeGetCurrent() let timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, […]

删除NSTimer / UITableViewCell实时?

我有一个UITableView ,我在每个UITableViewCell上设置了许多定时器。 每个计时器从用户在我的应用程序上创build“发布”开始,并应在24小时内过期。 但是,我想这样,当所有24小时结束时, UITableViewCell实时删除自己,但我似乎无法弄清楚我应该删除计时器的时间或地点。 我有一个方法,将不断刷新计时器每秒使用NSTimer.scheduledTimerWithTimeInterval ,它NSTimer.scheduledTimerWithTimeInterval更新每个UITableViewCell上的计时器。 但是,我无法find一个方法或find如何find每个UITableViewCell中的每个计时器是否完成。 很明显,我可以find如果计时器是在viewDidLoad完成,但只有在视图变为活动状态时调用。 有没有我缺less的方法或任何我可以用来查找是否通过scheduledTimerWithTimeInterval方法计时器完成,如果是,删除它? 这里是我的代码如下: //I have a self.offers array declared in the beginning of my class whcih will act as the UITableView data source. var offers = [Offer]() func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { //Dequeue a "reusable" cell let cell = tableView.dequeueReusableCellWithIdentifier(offerCellIdentifier) as! OfferCell setCellContents(cell, […]

如何在Objective-C / iOS中创build一个精确的计时器事件?

我期待在iOS上为SMPTE时间码(HH:MM:SS:FF)创build一个倒数计时器。 基本上,这只是一个分辨率为33.33333ms的倒数计时器。 我不太确定NSTimer是否足够准确,可以指望触发事件来创build此计时器。 每次这个计时器增加/减less时,我想发起一个事件或者调用一段代码。 我是Objective-C的新手,所以我正在从社区寻求智慧。 有人提出了CADisplayLink类,寻找一些专家的意见。

由CACurrentMediaTime()引起的架构i386编译错误的未定义符号

我正在做一个iOS应用程序显示一个计时器。 我不认为我可以让用户按下主页button后保持定时器运行,所以我想logging用户退出应用程序的时间,并使用重新进入应用程序更新定时器的时间。 这是我试过的代码: – (void)applicationWillResignActive:(UIApplication *)application { double currentTime = CACurrentMediaTime(); NSLog(@"%g", currentTime); /* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins […]

如何在iOS 7中超过180秒后运行NSTimer?

我已经尝试过,但在iOS 7和Xcode 4.6.2中不能工作超过180秒。 请帮帮我 UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid; UIApplication *app = [UIApplication sharedApplication]; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:bgTask]; }]; NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(timerMethod) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; -(void) timerMethod{ NSLog(@"in timerMethod"); }

如何创build倒数计时器的循环进度指示器

我正在尝试为我的应用程序添加一个倒计时,并且在animation中遇到了问题。 我要去看的外观类似于下面显示的iPad倒计时,随着时钟倒数,红色条会增加。 最初,我创build了一个图像地图集,每倒计时半秒钟一个单独的图像,但这似乎需要大量的内存运行,因此崩溃的应用程序,所以我现在必须find一个替代scheme。 我一直在着色着色https://developer.apple.com/library/prerelease/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Sprites/Sprites.html#//apple_ref/doc/uid/TP40013043-CH9看不到一种将精灵的一部分着色的方式,似乎整个精灵都会被改变。 有没有人知道如果着色会是一个select,或者有没有一种方法来减less图像使用的地图集? 谢谢