From 1fa1cc3dde87067c19697a1ac31e298b7c53ecad Mon Sep 17 00:00:00 2001 From: cnliucheng Date: Thu, 6 Aug 2026 10:40:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E7=8E=87=E8=87=AA=E9=80=82=E5=BA=94=E7=9C=81=E7=94=B5=20+=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=A9=BA=E6=A1=A5=E6=8E=A5=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 刷新率自适应: * 翻页动画进行中保持 60fps 保证流畅;静止时自动降频 * 显示秒时空闲降到 0.1s(10fps,跨秒检测延迟≤0.1s 不可见) * 关闭秒显示后空闲降到 1.0s 进一步省电 * 静止且无变化时跳过整屏重绘(setNeedsDisplay),仅保留低频轮询 - 删除空的 FlipClockSaver-Bridging-Header.h,并移除 pbxproj 中 SWIFT_OBJC_BRIDGING_HEADER 与 membershipExceptions 相关引用 (项目无 Obj-C 代码,桥接头多余) - Release 构建 BUILD SUCCEEDED,Developer ID 正式签名 + 验证通过 --- FlipClockSaver.xcodeproj/project.pbxproj | 15 ---------- .../FlipClockSaver-Bridging-Header.h | 4 --- FlipClockSaver/FlipClockSaverView.swift | 30 +++++++++++++++---- FlipClockSaver/FlipDigit.swift | 3 ++ 4 files changed, 27 insertions(+), 25 deletions(-) delete mode 100644 FlipClockSaver/FlipClockSaver-Bridging-Header.h diff --git a/FlipClockSaver.xcodeproj/project.pbxproj b/FlipClockSaver.xcodeproj/project.pbxproj index 33c2659..d35b886 100644 --- a/FlipClockSaver.xcodeproj/project.pbxproj +++ b/FlipClockSaver.xcodeproj/project.pbxproj @@ -10,22 +10,9 @@ 7B3DB23F3022DC2F00B3B568 /* FlipClockSaver.saver */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FlipClockSaver.saver; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ -/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */ - 7B3DB24E3022DC6000B3B568 /* Exceptions for "FlipClockSaver" folder in "FlipClockSaver" target */ = { - isa = PBXFileSystemSynchronizedBuildFileExceptionSet; - membershipExceptions = ( - "FlipClockSaver-Bridging-Header.h", - ); - target = 7B3DB23E3022DC2F00B3B568 /* FlipClockSaver */; - }; -/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */ - /* Begin PBXFileSystemSynchronizedRootGroup section */ 7B3DB2413022DC2F00B3B568 /* FlipClockSaver */ = { isa = PBXFileSystemSynchronizedRootGroup; - exceptions = ( - 7B3DB24E3022DC6000B3B568 /* Exceptions for "FlipClockSaver" folder in "FlipClockSaver" target */, - ); path = FlipClockSaver; sourceTree = ""; }; @@ -275,7 +262,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; STRING_CATALOG_GENERATE_SYMBOLS = YES; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_OBJC_BRIDGING_HEADER = "FlipClockSaver/FlipClockSaver-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 6.0; WRAPPER_EXTENSION = saver; @@ -303,7 +289,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; STRING_CATALOG_GENERATE_SYMBOLS = YES; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_OBJC_BRIDGING_HEADER = "FlipClockSaver/FlipClockSaver-Bridging-Header.h"; SWIFT_VERSION = 6.0; WRAPPER_EXTENSION = saver; }; diff --git a/FlipClockSaver/FlipClockSaver-Bridging-Header.h b/FlipClockSaver/FlipClockSaver-Bridging-Header.h deleted file mode 100644 index 1b2cb5d..0000000 --- a/FlipClockSaver/FlipClockSaver-Bridging-Header.h +++ /dev/null @@ -1,4 +0,0 @@ -// -// Use this file to import your target's public headers that you would like to expose to Swift. -// - diff --git a/FlipClockSaver/FlipClockSaverView.swift b/FlipClockSaver/FlipClockSaverView.swift index b47b081..a36de31 100644 --- a/FlipClockSaver/FlipClockSaverView.swift +++ b/FlipClockSaver/FlipClockSaverView.swift @@ -126,23 +126,41 @@ final class FlipClockSaverView: ScreenSaverView { refreshInfo() } - override var animationTimeInterval: TimeInterval { - get { 1.0 / 60 } - set {} - } + // 刷新率自适应:翻页动画进行中用 60fps 保证流畅;静止时自动降频省电。 + // 显示秒时仍需逐秒检测是否跨秒,空闲降到 0.1s(10fps,检测延迟≤0.1s 不可见); + // 关闭秒显示后只在整分翻动,空闲可降到 1.0s 进一步省电。 + private static let animFrameInterval: TimeInterval = 1.0 / 60.0 + private static let idleFrameInterval: TimeInterval = 0.1 + private static let idleNoSecondsFrameInterval: TimeInterval = 1.0 override func animateOneFrame() { let now = CACurrentMediaTime() frameTime = now let comps = Calendar.current.dateComponents([.hour, .minute, .second], from: Date()) let key = (comps.hour ?? 0) * 3600 + (comps.minute ?? 0) * 60 + (comps.second ?? 0) - if key != lastKey { + let keyChanged = key != lastKey + if keyChanged { lastKey = key update(animated: true, at: now) } + let wasAnimating = digits.contains { $0.isAnimating } for d in digits { d.advance(to: now) } + let isAnimating = digits.contains { $0.isAnimating } + let justFinished = wasAnimating && !isAnimating syncSettingsIfNeeded(now: now) - setNeedsDisplay(bounds) + + // 自适应刷新率:动画进行中保持 60fps;静止时降到低频省电 + let desired = isAnimating + ? Self.animFrameInterval + : (showSeconds ? Self.idleFrameInterval : Self.idleNoSecondsFrameInterval) + if abs(animationTimeInterval - desired) > 0.0001 { + animationTimeInterval = desired + } + + // 仅在“跨秒 / 动画中 / 动画刚结束”时才重绘,彻底静止时不触发整屏重绘 + if keyChanged || isAnimating || justFinished { + setNeedsDisplay(bounds) + } } // 轮询兜底:即使通知未送达(如跨进程/模块缓存),也能在约 0.5 秒内同步设置 diff --git a/FlipClockSaver/FlipDigit.swift b/FlipClockSaver/FlipDigit.swift index 2dd5b9a..e82ace0 100644 --- a/FlipClockSaver/FlipDigit.swift +++ b/FlipClockSaver/FlipDigit.swift @@ -27,6 +27,9 @@ final class FlipDigit { } } + /// 是否正处于翻页动画中(供视图判断是否需要高刷新率) + var isAnimating: Bool { animating } + func draw(in ctx: CGContext, rect: CGRect, radius: CGFloat,