Code Monkey home page Code Monkey logo

Comments (3)

pawello2222 avatar pawello2222 commented on August 16, 2024 2

@liudhzhyym @mromanuk Thanks for the question.

According to Apple it can't be done.

Here you can find a comment made by a Systems Engineer from Apple:

[...] However, you cannot update views to the time other than the relative date text label. So you cannot replicate the Clock widget for example and have second hands on a clock tick by while the widget is visible. Sorry.

Also, from the Human Interface Guidelines for Widgets:

Keep your widget up-to-date. To remain relevant and useful, widgets should periodically refresh their information. Widgets don’t support continuous, real-time updates, and the system may adjust the limits for updates depending on various factors.

My understanding is that the only way for third-party apps to provide such animations is to use private API. The system Clock Widget does this after all, so it might actually be possible to replicate this behaviour using some private methods that I'm not aware of.

I didn't really look into it myself yet (will probably do when I have more time) but in the meantime you can see this post for a starter:

from widgetexamples.

mromanuk avatar mromanuk commented on August 16, 2024

I want to add a homescreen widget to my app, just like the iOS system Clock app, the second hand keeps moving every second. I have been searching on Google and Github for a long time and have not found a suitable solution. I have seen that there are already third-party apps that can implement such desktop widgets.

Do you know how do they do it?

I saw the same, I'm building a Widget App and I would like to have the sub second hand on my clock. Did you find out?

from widgetexamples.

pawello2222 avatar pawello2222 commented on August 16, 2024

@liudhzhyym @mromanuk

It looks like the private method you were looking for is _clockHandRotationEffect:

extension SwiftUI.View {
  @available(iOS 14.0, macOS 11, *)
  @available(tvOS, unavailable)
  @available(watchOS, unavailable)
  public func _clockHandRotationEffect(_ period: WidgetKit._ClockHandRotationEffect.Period, in timeZone: Foundation.TimeZone, anchor: SwiftUI.UnitPoint = .center) -> some SwiftUI.View
}

If you'd like to investigate it more, this code can be found in the WidgetKit framework module.

As I mentioned in the post above, the whole tutorial can be found here:

And here's the path to the original WidgetKit module:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/WidgetKit.framework/Modules/WidgetKit.swiftmodule

Please bear in mind that this is a private method and not approved by Apple - it may stop working any time or your app might be rejected (even after initially approved).

from widgetexamples.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.