- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
这个计时器不是每秒触发一次,当我检查日志和 UI 时,它似乎每 3-4 秒触发一次。
func startTimer() {
print("start timer")
timer = Timer.scheduledTimer(timeInterval: 1,
target: self,
selector: #selector(timerDidFire),
userInfo: nil,
repeats: true)
}
func timerDidFire(timer: Timer) {
print("timer")
updateLabels()
}
这只是由于功能不足而在 Watch 上发生的事情,还是我的代码有问题?
如果需要,这里是日志:
0.0396000146865845
3.99404102563858
7.97501903772354
11.9065310359001
编辑:
澄清一下,我每秒更新的是锻炼计时器,因此它需要每秒更新一次。
最佳答案
如果您的应用正忙于做其他事情,这会阻止或延迟运行循环检查触发时间是否已重复过去,the timer will only fire once during that period :
A repeating timer always schedules itself based on the scheduled firing time, as opposed to the actual firing time. For example, if a timer is scheduled to fire at a particular time and every 5 seconds after that, the scheduled firing time will always fall on the original 5 second time intervals, even if the actual firing time gets delayed. If the firing time is delayed so far that it passes one or more of the scheduled firing times, the timer is fired only once for that time period; the timer is then rescheduled, after firing, for the next scheduled firing time in the future.
顺便说一句,根据对更改的响应(例如,观察)或对事件的 react (例如,完成处理程序)来更新您的 UI 可能会更有效。
如果在计时器间隔期间没有任何更改,这可以避免在驱动检查但实际上没有要执行的 UI 更新时为应用创建繁忙的工作。
它还可以防止触发间隔内的多次更改被忽略,因为计时器驱动的模式只会在 UI 中显示最后一次更改。
关于swift - 计时器不会在 WatchKit 上每秒触发一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38937786/
我正在尝试创建一个 iOS WatchOS5 复杂功能,并且看到了许多教程和苹果文档。他们谈论: WatchKit 应用 WatchKit 应用扩展 iOS WatchKit 应用程序和 WatchK
我正在 Storyboard 中设置一个菜单和菜单项,并且希望一个菜单项在两种状态之间切换,例如开/关、摄氏度/华氏度等 但是,从菜单项按住控制拖动到界面 Controller 并不能让我创建导出,而
我必须将数据从我的 watchkit 发送到另一个 watchkit。可能吗 ?如果是,那么实现它的方法是什么? 我知道如何通过 [WKInterfaceController openParentAp
我在编译 watchkit 应用程序时遇到此错误 嵌入式二进制验证实用程序错误 error: WatchKit Extension contains multiple WatchKit apps wh
我们有一个分层的 watch 应用程序。 根 Controller 是一个菜单项表。该项目列表由服务器控制。数据被检索并存储在核心数据中。第一次进入应用程序时会填充菜单。 但我希望这张表保持最新。我的
我的应用程序显示各种倒数计时器,用户将查看这些计时器以了解何时执行各种任务。当应用程序位于前台时,我希望此屏幕继续显示在 watch 上。目前,屏幕会自动关闭,如果我不甩手腕,应用程序甚至会暂停。 这
谁能帮我编写一份示例代码,以便在 Apple Watchkit 应用中添加语音到文本转换功能。 最佳答案 是的,这是可能的。这是文档: https://developer.apple.com/libr
关于这个问题有几篇文章,但没有一个建议的解决方案适用于我的情况。我正在尝试按照 Apple 提供的说明将 WatchKit 集成到一个简单的示例应用程序中(我现在已经尝试了几个)。编译时出现以下错误消
昨天我saw this post并让我意识到我有问题。 在商店中有 WatchOS1 应用程序后,我创建了一个 WatchOS2 应用程序。当我尝试运行该应用程序时 made me upgrade m
iOS可以使用layer.cornerRadius打个圆UIButton . 是否WKInterfaceButton有这个属性吗? 如果没有,我怎么才能圆WKInterfaceButton在 Watc
错误信息: This app contains multiple WatchKit 2.0 apps. Only a single WatchKit 2.0 app is allowed. Watch
好吧,这是非常基本的,但我已经一遍又一遍地阅读了文档,并想确保我做对了。用通俗易懂的语言来说,我的 watchkit 应用程序将因退出我的代码外部应用程序的某些用户交互而关闭,对吗?我不需要使用任何类
在具有 WatchKit 扩展和 WatchKit 应用程序 - 目标的 xcode 项目中。如果我重命名目标 - 从例如:“Sample WatchKit App”和“Sample WatchKit
如果我将界面 Storyboard 的自定义类放在 WatchKit 或 WatchKist 扩展中,会有什么不同。 (以 myInterfaceController 为例) 最佳答案 您的 Watc
我有一个支持 Watchkit 的应用程序。当我在 iPhone 上运行该应用程序时,它构建良好,但在 Xcode 中显示警告“WatchKit 应用程序具有无效的 stub 可执行文件”。我已正确使
我在 WKExtensionDelegate 和 WKInterfaceController 上都添加了日志。 这是我在玩启动和退出应用程序时得到的结果 观看操作系统模拟器。 (模拟器运行 watch
验证 WatchKit 应用的 Info.plist 中 WKWatchKitApp 的值是否设置为 YES。 最佳答案 经过数周又数周的调查,我终于发现了问题所在。 Iphone App的产品名称与
我今天尝试将我的应用程序加载到 iTunesConnect,但在重新构建期间出现错误。没有找到配置文件(当我只为我的 iPhone 应用程序运行它时,它工作得很好并且已经有一段时间了)。所以我认为这是
我正在尝试将我的 Apple Watch 应用上传到 iTunes,每次我上传我的二进制文件时,我都会收到来自苹果团队的以下邮件。我已经完成了我的以下 list 。 为 watchapp 和扩展程序创
好的。在经典 iOS 中做到这一点很容易,但 WatchKit 不提供任何 block /闭包,并且在带/不带动画之间没有选择。 我有一个根 Controller ,其中有一个选项列表。触摸其中一个选
我是一名优秀的程序员,十分优秀!