iOS 灵动岛 ActivityKit 开发实践
灵动岛的创建和基本介绍
https://juejin.cn/post/7220962923736072252
关键记录
需求: 实现灵动岛上靠右显示的倒计时
Text(timerInterval: <#T##ClosedRange<Date>#>,countsDown: <#T##Bool#>).multilineTextAlignment(.leading)
1. multilineTextAlignment(.leading)
效果靠右显示
2. countsDown
Bool 值,true 倒计时,false 正计时
3. timerInterval
传入一个时间区间
倒计时:开始时间传当前时间,结束时间传入 当前时间+倒计时长
正计时:开始时间传当前时间-当前计时,结束时间 当前时间+计时总时长
var timerInterval: ClosedRange<Date> =isDown? Date()...Date().addingTimeInterval(TimeInterval(totalSeconds)): Date().addingTimeInterval(-TimeInterval(currentSeconds))...Date().addingTimeInterval(TimeInterval(300*60))
跳转路由配置
-
点击整块内容,给最外层控件添加路由
-
单独子控件路由
// 🔹 单独按钮用 LinkLink(destination: URL(string: "**/activity/stopTimer")!) {Text("结束计时").font(.system(size: 12)).frame(width: 68, height: 22).foregroundColor(Color(hex: "#6BAFEB")).background(Color.white).overlay(RoundedRectangle(cornerRadius: 11).stroke(Color(hex: "#B8DDFF"), lineWidth: 1)).cornerRadius(11)}
处理路由
AppDelegate 文件
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {let str = url.absoluteStringif str.contains("**/activity/stopTimer") {}
}
感谢您的阅读和参与,HH思无邪愿与您一起在技术的道路上不断探索。如果您喜欢这篇文章,不妨留下您宝贵的赞!如果您对文章有任何疑问或建议,欢迎在评论区留言,我会第一时间处理,您的支持是我前行的动力,愿我们都能成为更好的自己!