Skip to content

About

WidgetKit clock hand rotation effect, works on Xcode 26.1+

Topics

Resources

Contributing

Stars

29 stars

Watchers

2 watching

Forks

Repository files navigation

ClockHandKit

ClockHandKit

A framework for continuous animation in iOS widgets.

GitHub stars Latest release Swift 6.2 iOS 16 or later Xcode 26.1 or later MIT License

English · 한국어


Apple turns the hands of its Clock widget with _ClockHandRotationEffect. But it's a private WidgetKit API, so other apps don't get it. ClockHandKit builds this effect at runtime and applies it, so widgets in your own apps can use it too.

ClockHandRotationKit used to do the same thing, but it stopped working in apps built with Xcode 26.1 or later on iOS 26.1. The _clockHandRotationEffect() function it relied on now returns the view unchanged in third-party apps, without adding the effect. So I made a new framework that skips that function and builds the _ClockHandRotationEffect it used internally. 😆

See the release notes for details.

ClockHandKit rotating on a real device next to ClockHandRotationKit

Left: ClockHandKit
Right: the original ClockHandRotationKit on iOS 26.1 and later

Installation

Swift Package Manager

.package(url: "https://github.com/giljihun/ClockHandKit.git", from: "0.1.2")

Usage and how it works

import SwiftUI
import ClockHandKit

ZStack {
    hourHand.clockHandRotationEffect(period: .hourHand)
    minuteHand.clockHandRotationEffect(period: .minuteHand)
    secondHand.clockHandRotationEffect(period: .secondHand)
}

Set the time zone with in and the pivot with anchor.

secondHand.clockHandRotationEffect(period: .secondHand, in: .gmt, anchor: .bottom)

Frame animation

The effect turns a view by the current time, without waiting for a new timeline entry. Place frames around a wheel and show one slot at a time through a fixed viewport. As the wheel turns, the frames play like an animation.

Frame animation created with a rotating wheel

// A frame wheel built by your app with eight slots
frameWheel
    .clockHandRotationEffect(period: .custom(8))

period is the time for one full 360° turn, not the length of a single frame.

period = total frame slots / target FPS

For one copy of a 120-frame sequence:

Target rate period
12 FPS 10 seconds
24 FPS 5 seconds
30 FPS 4 seconds
60 FPS 2 seconds

These are targets. WidgetKit and the device decide the actual rendering cadence.

Example

Examples/ClockHandExample contains an app with a clock widget.

For frame animation, see KeyringWidget, a swinging keyring widget built with ClockHandKit.

Migrating from ClockHandRotationKit

Replace the import.

-import ClockHandRotationKit
+import ClockHandKit

Existing calls such as .clockHandRotationEffect(period: 60) keep working. For new code, the typed API reads better: .clockHandRotationEffect(period: .secondHand).

ClockHandKit requires iOS 16 or later. Don't import both modules into the same target, because their extension methods can conflict.

Acknowledgements ❤️

ClockHandKit started from octree/ClockHandRotationKit, which I contributed to as a collaborator. My heartfelt thanks to octree for all the inspiration. ❤️

License

ClockHandKit is available under the MIT License.

About

WidgetKit clock hand rotation effect, works on Xcode 26.1+

Topics

Resources

Contributing

Stars

29 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages