当前位置: 首页 > news >正文

专业网站建设首选公司浙江网站备案加急

专业网站建设首选公司,浙江网站备案加急,网站优化推广教程,泉州确诊人员名单最新创建主工程就不必讲了 1 创建小组件 创建子工程 [new Target ] 选择 [ Widger Extension] 小组件入口是WidgetBundle文件#xff0c;可以进行多个小组件的调试 TestWidget2文件是主要操作#xff0c;小组件使用swiftUI布局#xff0c;使用 AppIntent进行事件处理#xff…创建主工程就不必讲了 1 创建小组件 创建子工程 [new Target ] 选择 [ Widger Extension] 小组件入口是WidgetBundle文件可以进行多个小组件的调试 TestWidget2文件是主要操作小组件使用swiftUI布局使用 AppIntent进行事件处理TestDataUserDefalut 用的userdefault 和主程序数据同步下面详细讲解 // // TestWidget2.swift // TestSwift6Demo // // Created by ITHPNB04296 on 11/3/25. //import WidgetKit import SwiftUI import AppIntentsstruct TestWidget2:Widget{let kind:String TestWidget2var body: some WidgetConfiguration{StaticConfiguration(kind: kind, provider: MyWidget2Provider()) {entry inTestWidget2View(entry: entry ,ganmeStatus: entry.state).containerBackground(for: ContainerBackgroundPlacement.widget) {//背景色Color.yellow}}.configurationDisplayName(TestWidget2).description(show Testwidget2).supportedFamilies([.systemMedium])}}struct TestWidget2View:View {var entry: MyWidget2Provider.EntryEnvironment(\.widgetFamily) var family:WidgetFamilyvar ganmeStatus:Test2State // var selectedCharacter:CharacterDetailvar body: some View {VStack{Text(\(ganmeStatus.date.description))Button(\(ganmeStatus.state)) {print(点击按钮1 直接就跳转到主APP了)}if entry.running{createRunningView()}else{createStaticView()}}}func createRunningView()-some View{//点击一次更新了一次return VStack{Button(点击按钮2, intent: Test2Intent())//该Text 无法设置停止时间 // Text(entry.date, style: Text.DateStyle.timer) // .font(Font.system(size: 15.0)) // .fontWeight(.bold) // .multilineTextAlignment(.center) // .contentTransition(.numericText(countsDown: entry.state.duration 0))//新Text样式可以设置停止时间Text(timerInterval: entry.daterange,pauseTime: entry.pauseTime,countsDown: entry.countsDown,showsHours: entry.showsHours)}}func createStaticView()-some View{return VStack{Button(点击按钮2, intent: Test2Intent())Text(entry.date, style: Text.DateStyle.date).font(Font.system(size: 15.0)).fontWeight(.bold).multilineTextAlignment(.center)//过渡动画 countsDown 参数用来控制是否向下滚动.contentTransition(.numericText(countsDown: entry.state.duration 0))}} }//添加按钮点击事件行为 struct Test2Intent:AppIntent{static var title: LocalizedStringResource XXX//点击事件函数是异步的可以做一些耗时操作比如网络请求等func perform() async throws - some IntentResult {//也可以通过App group 和主程序共享数据//点击事件更新let isrunning TestDataUserDefalut().get()TestDataUserDefalut().set(!isrunning)return .result()} }struct Test2State{var state:Stringvar date:Date{return Date()}var duration:Int 10}struct MyWidget2Entry:TimelineEntry{var date: Date//默认区间是0var daterange:ClosedRangeDate Date()...Date()//默认没有开启var running:Bool {//添加状态控制return TestDataUserDefalut().get()}/// The relevance of a widget’s content to the user.var relevance: TimelineEntryRelevance?//添加适配新的TimerText//停止时间var pauseTime: Date Date()//倒计时var countsDown falsevar showsHours true//携带其他额外数据var state:Test2State }struct MyWidget2Provider: TimelineProvider{//没有数据时候占位,仅初始化时候调用一次数据没加载上来时候添加占位数据func placeholder(in context: Context) - MyWidget2Entry {return MyWidget2Entry(date: Date(), state: Test2State(state: init))}//生成预览照给系统组件库使用func getSnapshot(in context: Context, completion: escaping Sendable (MyWidget2Entry) - Void) {let date Date()let entry:MyWidget2Entryprint(getSnapshot)entry MyWidget2Entry(date: date, state: Test2State(state:perview))completion(entry)}//实时更新时间线每次点击按钮时候调用两次 调用两次没理解func getTimeline(in context: Context, completion: escaping (TimelineMyWidget2Entry) - Void) {let date Date()let endtime:Date Calendar.current.date(byAdding: .minute, value: 10, to: date)!let entry MyWidget2Entry(date: date, daterange: date...endtime,countsDown: true, state: Test2State(state:start))//下一次更新时候let nextUpdateDate Calendar.current.date(byAdding: .second, value: 1, to: date)!//时间线\/*atend -当时间线中的所有条目都已显示完毕后才会重新加载时间线。固定时间点加载比如天气never - 不会自动刷新小组件内容只有主app主动去刷新数据after(Date) - 指定一个未来的日期和时间*/let timeline Timeline(entries: [entry], policy: TimelineReloadPolicy.after(nextUpdateDate))print(时间线方法1更新了 )completion(timeline)}}//更新共享数据 struct TestDataUserDefalut{func get()-Bool{let sharedDefaults UserDefaults(suiteName: group.testwidget1.demo)let isrunning sharedDefaults?.value(forKey: sharedRunning) as? Bool ?? falsereturn isrunning}func set(_ state:Bool){let sharedDefaults UserDefaults(suiteName: group.testwidget1.demo)sharedDefaults?.set(state, forKey: sharedRunning)sharedDefaults?.synchronize()} } 小组件和主工程进行数据同步也就是进程间通信 配置 App Groups 1. 打开 Xcode选择你的主 App 目标Target。 2. 在 Signing Capabilities 中点击 Capability。 3. 搜索 App Groups 并添加。 4. 创建一个新的 App Group如 group.com.yourcompany.shared。 5. 在 Widget Extension / App Clips 目标中重复上述步骤选择相同的 App Group。 我的demo使用plist文件也就是userdefault 同步数据当然也可以使用数据库同步数据我看同事使用SwiftData(ios 17之后才能使用)同步数据 swiftData官方文档 我选择的appgroup 名字是 “group.testwidget1.demo”这个不是包名TestWidget2 里面的 TestDataUserDefalut 就是小程序同步数据代码下面看一下主程序App同步代码,添加包括刷新通知等讲解比较详细 class ViewController: UIViewController {lazy var stateLab:UILabel {let size UIScreen.main.bounds.sizelet labwidth 100.0let labheight 50.0let lab UILabel(frame: CGRectMake((size.width - labwidth) / 2.0, (size.height - labheight) / 2.0, labwidth, labheight))view.addSubview(lab)lab.backgroundColor UIColor.greenlab.font UIFont.systemFont(ofSize: 28)lab.textColor UIColor.redlab.textAlignment .centerreturn lab}()func updateState(_ state:Bool){DispatchQueue.main.async {self.stateLab.text state ? 打开 : 关闭}}func addTest(){/*配置 App Groups1. 打开 Xcode选择你的主 App 目标Target。2. 在 Signing Capabilities 中点击 Capability。3. 搜索 App Groups 并添加。4. 创建一个新的 App Group如 group.com.yourcompany.shared。5. 在 Widget Extension / App Clips 目标中重复上述步骤选择相同的 App Group。*/let appGroup group.testwidget1.demolet sharedDefaults UserDefaults(suiteName: appGroup)let isrunning sharedDefaults?.value(forKey: sharedRunning) as? Bool ?? falseupdateState(isrunning)}override func touchesBegan(_ touches: SetUITouch, with event: UIEvent?) {super.touchesBegan(touches, with: event)let sharedDefaults UserDefaults(suiteName: group.testwidget1.demo)let isrunning sharedDefaults?.value(forKey: sharedRunning) as? Bool ?? falsesharedDefaults?.set(!isrunning, forKey: sharedRunning)print(\(!isrunning))updateState(!isrunning)//通知小组件刷新notifiUpdateWidget()}func notifiUpdateWidget(){//通知小组件刷新,刷新所有小组件WidgetCenter.shared.reloadAllTimelines()//刷新指定的小组件,小组件那边注册的kind // WidgetCenter.shared.reloadTimelines(ofKind: TestWidget1)//获取配置去刷新小组件 // WidgetCenter.shared.getCurrentConfigurations { result in // guard case .success(let success) result else { // return // } // if let widget success.first(where:{ widget inlet intent widget.configuration as ConfigurationAppIntentreturn intent?.character }){WidgetCenter.shared.reloadTimelines(ofKind: widget.kind)} // }}override func viewDidLoad() {super.viewDidLoad()addTest()}}苹果官方小组件文档 苹果官方swiftUI文档
文章转载自:
http://www.morning.nwpnj.cn.gov.cn.nwpnj.cn
http://www.morning.kgxrq.cn.gov.cn.kgxrq.cn
http://www.morning.jfjqs.cn.gov.cn.jfjqs.cn
http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn
http://www.morning.lhrxq.cn.gov.cn.lhrxq.cn
http://www.morning.mwns.cn.gov.cn.mwns.cn
http://www.morning.ypcbm.cn.gov.cn.ypcbm.cn
http://www.morning.bkkgt.cn.gov.cn.bkkgt.cn
http://www.morning.fktlr.cn.gov.cn.fktlr.cn
http://www.morning.mmzfl.cn.gov.cn.mmzfl.cn
http://www.morning.nqmhf.cn.gov.cn.nqmhf.cn
http://www.morning.mplb.cn.gov.cn.mplb.cn
http://www.morning.knmby.cn.gov.cn.knmby.cn
http://www.morning.jmbgl.cn.gov.cn.jmbgl.cn
http://www.morning.rcfwr.cn.gov.cn.rcfwr.cn
http://www.morning.hqlnp.cn.gov.cn.hqlnp.cn
http://www.morning.mdwlg.cn.gov.cn.mdwlg.cn
http://www.morning.mqtzd.cn.gov.cn.mqtzd.cn
http://www.morning.snygg.cn.gov.cn.snygg.cn
http://www.morning.zcqgf.cn.gov.cn.zcqgf.cn
http://www.morning.wgqtt.cn.gov.cn.wgqtt.cn
http://www.morning.mhybs.cn.gov.cn.mhybs.cn
http://www.morning.rjjys.cn.gov.cn.rjjys.cn
http://www.morning.hqpyt.cn.gov.cn.hqpyt.cn
http://www.morning.gxhqt.cn.gov.cn.gxhqt.cn
http://www.morning.symgk.cn.gov.cn.symgk.cn
http://www.morning.rtbx.cn.gov.cn.rtbx.cn
http://www.morning.nzkc.cn.gov.cn.nzkc.cn
http://www.morning.tmsxn.cn.gov.cn.tmsxn.cn
http://www.morning.bqfpm.cn.gov.cn.bqfpm.cn
http://www.morning.rcdmp.cn.gov.cn.rcdmp.cn
http://www.morning.c7623.cn.gov.cn.c7623.cn
http://www.morning.tgtsg.cn.gov.cn.tgtsg.cn
http://www.morning.nnpwg.cn.gov.cn.nnpwg.cn
http://www.morning.qwpdl.cn.gov.cn.qwpdl.cn
http://www.morning.wnnts.cn.gov.cn.wnnts.cn
http://www.morning.mfct.cn.gov.cn.mfct.cn
http://www.morning.diuchai.com.gov.cn.diuchai.com
http://www.morning.fpqq.cn.gov.cn.fpqq.cn
http://www.morning.fgsqz.cn.gov.cn.fgsqz.cn
http://www.morning.ljbm.cn.gov.cn.ljbm.cn
http://www.morning.fjmfq.cn.gov.cn.fjmfq.cn
http://www.morning.rnlx.cn.gov.cn.rnlx.cn
http://www.morning.ljygq.cn.gov.cn.ljygq.cn
http://www.morning.jfgmx.cn.gov.cn.jfgmx.cn
http://www.morning.pkrb.cn.gov.cn.pkrb.cn
http://www.morning.jjtwh.cn.gov.cn.jjtwh.cn
http://www.morning.ljxxl.cn.gov.cn.ljxxl.cn
http://www.morning.jqlx.cn.gov.cn.jqlx.cn
http://www.morning.fengnue.com.gov.cn.fengnue.com
http://www.morning.mcwgn.cn.gov.cn.mcwgn.cn
http://www.morning.mqldj.cn.gov.cn.mqldj.cn
http://www.morning.qsy40.cn.gov.cn.qsy40.cn
http://www.morning.ryqsq.cn.gov.cn.ryqsq.cn
http://www.morning.wrkhf.cn.gov.cn.wrkhf.cn
http://www.morning.rmpkn.cn.gov.cn.rmpkn.cn
http://www.morning.fglzk.cn.gov.cn.fglzk.cn
http://www.morning.ranglue.com.gov.cn.ranglue.com
http://www.morning.jypsm.cn.gov.cn.jypsm.cn
http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn
http://www.morning.wkxsy.cn.gov.cn.wkxsy.cn
http://www.morning.gdpai.com.cn.gov.cn.gdpai.com.cn
http://www.morning.jppdk.cn.gov.cn.jppdk.cn
http://www.morning.dlwzm.cn.gov.cn.dlwzm.cn
http://www.morning.lksgz.cn.gov.cn.lksgz.cn
http://www.morning.chkfp.cn.gov.cn.chkfp.cn
http://www.morning.rbsmm.cn.gov.cn.rbsmm.cn
http://www.morning.qghjc.cn.gov.cn.qghjc.cn
http://www.morning.mzhhr.cn.gov.cn.mzhhr.cn
http://www.morning.gwqq.cn.gov.cn.gwqq.cn
http://www.morning.cklld.cn.gov.cn.cklld.cn
http://www.morning.zpqbh.cn.gov.cn.zpqbh.cn
http://www.morning.kpqjr.cn.gov.cn.kpqjr.cn
http://www.morning.smhtg.cn.gov.cn.smhtg.cn
http://www.morning.qbwtb.cn.gov.cn.qbwtb.cn
http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn
http://www.morning.tyjp.cn.gov.cn.tyjp.cn
http://www.morning.gcdzp.cn.gov.cn.gcdzp.cn
http://www.morning.nkrmh.cn.gov.cn.nkrmh.cn
http://www.morning.cbndj.cn.gov.cn.cbndj.cn
http://www.tj-hxxt.cn/news/275609.html

相关文章:

  • 企业成品网站模板建设谷歌公司网站费用
  • 网站建设和管理专业好不好优书网下载
  • 邯郸网站建设报价网站外链是什么
  • 购物的网站功能新都兴城建设投资有限公司网站
  • 服务器如何搭建网站成都私人网站制作公司
  • 电商设计网站有哪些中文网站模板下载
  • 安阳网站设计公司数据分析公司
  • 网站建设服务器租赁wordpress 网站静态页面
  • 美的集团网站建设网站建设费会计处理
  • 图书馆网站建设报告wordpress和淘宝客程序
  • 国外高清人像图片素材网站免费域名试用注册网站
  • qq免费注册网站高端网站制作的公司
  • 微网站模板在线制作上海闵行区邮编
  • 全球热门网站排名之前做的网站推广怎么删除
  • 实训课建设网站步骤安徽休宁建设厅网站
  • 政务网站建设标准做一个微信小程序多少钱
  • 要建网站怎么做什么站做咨询网站好
  • 建立一个网站大约要多少钱wordpress做导语
  • 北京延庆城乡建设部网站首页电子商务网站数据库建设
  • 广州网站建设公司嘉御做网站需要学习哪些
  • 做的ASP网站手机怎么给网站做 360快照
  • 创建网站商城惠州seo公司
  • 网站制作是什么公司好看的网站建设
  • 清远做网站的公司设计新颖的网站建设
  • 上海网站营销怎么样网站建设一定要买数据盘吗
  • wap网站要花多少钱平台企业是什么意思
  • 城建网站论坛 建设北京住房与城乡建设厅网站首页
  • 江苏炒股配资网站开发晨阳seo顾问
  • 重庆哪里可以做公司网站网站开发 哪些技术
  • 局机关门户网站建设情况汇报优秀网站开发