watchOS2支持自定义表盘的Complication(苹果把表盘上显示的每一个控件称之为Complication)。苹果已经做使定制Complication在watchOS2的非常好的工作。WatchoOS现在包含ClockKit(表盘开发工具包),他包含了所有可定制化的Complication类型。自定义表盘的工作方式是非常简单的,只需要你的Watch Extension提供实现CLKComplicationDataSource协议,提供给ClockKit(表盘)数据。
Complication的五大分类:
一张图解释清楚:
Complication 布局
提供给表盘(ClockKit)显示元素主要是通过CKComplicationTemplate,每一种家族的表盘元素 (complication)都有特定的子类,共提供用23个子类:
通过自己的业务需求来选择数据展示所需模版。
Complication的Provider:
可以通过选择上面的模版来展示我们的数据。那么我们的数据如何显示在模版上的呢?我们可以通过设置模版的Providers(提供者),Providers是非常灵活的,提供了各种各样的Provider,如需要显示文本内容,我们有CLKTextProvider,它的子类CLKSimpleTextProvider非常常用,它有个text属性,设置这个属性提供给模版显示简单的文本内容。显示图片用CLKImageProvider提供给模版显示简单图片。使用CLKDateTextProvider,CLKTimeTextProvider和relativCLKRelativeDateTextProvider来为表盘显示时间。
/1.创建选择的模版 let tmpl = CLKComplicationTemplateModularLargeStandardBody() //2.使用Provider设置要显示的数据 tmpl.headerImageProvider = CLKImageProvider(onePieceImage:UIImage(named: "soccer_ball")!) tmpl.headerTextProvider = CLKTimeTextProvider(date: match.date!) tmpl.body1TextProvider = CLKSimpleTextProvider(text: match.teamDesc!) tmpl.body2TextProvider = CLKSimpleTextProvider(text: match.groupDesc!)
自动生成的:CLKComplicationDataSource:
@implementation ComplicationController #pragma mark - Timeline Configuration //时间线前后 - (void)getSupportedTimeTravelDirectionsForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTimeTravelDirections directions))handler { handler(CLKComplicationTimeTravelDirectionForward|CLKComplicationTimeTravelDirectionBackward); } //时间线起点 - (void)getTimelineStartDateForComplication:(CLKComplication *)complication withHandler:(void(^)(NSDate * __nullable date))handler { handler(nil); } //时间线终点 - (void)getTimelineEndDateForComplication:(CLKComplication *)complication withHandler:(void(^)(NSDate * __nullable date))handler { handler(nil); } //在锁屏时候是否隐藏Complication - (void)getPrivacyBehaviorForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationPrivacyBehavior privacyBehavior))handler { handler(CLKComplicationPrivacyBehaviorShowOnLockScreen); } #pragma mark - Timeline Population //获取当前complication - (void)getCurrentTimelineEntryForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTimelineEntry * __nullable))handler { // Call the handler with the current timeline entry handler(nil); } //获取limit个时间点前的complication - (void)getTimelineEntriesForComplication:(CLKComplication *)complication beforeDate:(NSDate *)date limit:(NSUInteger)limit withHandler:(void(^)(NSArray<CLKComplicationTimelineEntry *> * __nullable entries))handler { // Call the handler with the timeline entries prior to the given date handler(nil); } //获取limit个时间点后的complication - (void)getTimelineEntriesForComplication:(CLKComplication *)complication afterDate:(NSDate *)date limit:(NSUInteger)limit withHandler:(void(^)(NSArray<CLKComplicationTimelineEntry *> * __nullable entries))handler { // Call the handler with the timeline entries after to the given date handler(nil); } #pragma mark Update Scheduling //多久更新时间线 - (void)getNextRequestedUpdateDateWithHandler:(void(^)(NSDate * __nullable updateDate))handler { // Call the handler with the date when you would next like to be given the opportunity to update your complication content handler(nil); } #pragma mark - Placeholder Templates //complication的placeholder - (void)getPlaceholderTemplateForComplication:(CLKComplication *)complication withHandler:(void(^)(CLKComplicationTemplate * __nullable complicationTemplate))handler { // This method will be called once per supported complication, and the results will be cached handler(nil); } @end
感谢:
https://developer.apple.com/library/watchos/documentation/General/Conceptual/AppleWatch2TransitionGuide/DesigningaComplication.html#//apple_ref/doc/uid/TP40015234-CH11-SW1
http://blog.csdn.net/wangjavafans/article/details/47763423
相关推荐
configuration Activity for configuring both the watch face styles and the complications themselves. We recommend you reuse the configuration code and follow the UX patterns in your watch face's ...
You won't just be creating apps - with Glances to provide timely information, notifications to inform your users of the latest updates, and watch face complications to show your users data as soon as ...
"Boss-Template:Boss Watch Face 的来源"是一个专为Android智能穿戴设备应用"Face for Wear"设计的定制手表表面模板。这个项目展示了如何利用Java编程语言来创建具有高级特性的手表表面,为用户提供个性化的体验。 ...
本教程旨在帮助初学者快速掌握Apple Watch应用的开发技能,从而能够设计和构建自己的表盘并发症(Complications)以及独立的Watch应用程序。 一、Swift基础知识 Apple Watch开发主要使用Swift语言,这是一种由苹果...
8. **Complications**: 是Apple Watch特有的功能,它允许在表盘上展示实时信息。开发者可以自定义复杂功能,将应用程序的数据集成到用户的表盘上。 9. **HealthKit / HomeKit Integration**: 如果你的应用程序与...
The postoperative ICP in the early surgery group showed a trend of slowly increasing and then decreasing, with higher values on the 3rd and 5th days after surgery compared to the 1st day, reaching ...
6. **Complications**: 这是Apple Watch特有的特性,允许开发者在表盘上展示动态信息。你可以自定义多种类型的并发症,如数字、文字、图像或定制的图形。 7. **Notification**: Apple Watch可以接收并显示iPhone的...
The book’s focus on the practical aspects of the MongoDB implementation makes it an ideal purchase for developers charged with bringing MongoDB’s scalability to bear on the particular problem you’...
Twelveish-Wear OS(Android Wear)的表盘 Twelveish是独特的Wear OS(Android Wear)表盘,它以文字(多种语言)显示大致时间。 它还在顶部显示确切的时间(数字时钟)和星期几,在下方略微显示日期和电池百分比,...
If you are new to Swift 2, we suggest you read the Swift Apprentice, which takes you on a comprehensive tour through the Swift language, even if you are a complete beginner. If you are new to iOS, we ...
RFC3027:Protocol Complications with the IP Network Address Translator
This unique 2-in-1 reference presents vital... Icons highlight complications, life-threatening disorders, emergency interventions, and effects of treatment on disease processes.,解压密码 share.weimo.info
Providing a sound definition and review of the pertinent treatment goals for the management of adult lumbar scoliosis, this practical and comprehensive guide covers everything from pre-operative ...
For convenience, assume that none of the fields have spaces or commas in them, so you can read a comma separated file without worrying about those (non-algorithm related) complications. No need to ...
surgical approaches and techniques, and potential complications for the different spine regions. Each chapter contains concise, step-by-step descriptions of the procedures enhanced by clearly labeled...
neurological, endocrine, cardiovascular, respiratory, renal, gastrointestinal and reproductive disorders, their symptoms, complications and usual treatment along with the actions and uses of some ...
The value of parental report of family histories of reading disorders and pregnancy and birth complications in reading disabled and normal children THE VALUE OF PARENTAL REPORT OF FAMILY HISTORIES ...