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
相关推荐
Add functionality to the notification system, including actionable items, and display them on the Watch face Design and build complications, Watch-face gadgets that can display quick snapshots of ...
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 ...
meaning that this book is entirely about iOS 9 subjects, including but not limited to the followings: Apple watchOS 2: so that you can create complications and standalone ?Watch apps UI Testing: ...
Let Noel Rappin guide you through the setup and complications of dealing with online financial transactions. Go beyond just the interaction with the gateway service and build an application that will...
By concentrating on the principles that make the theory work in practice, the author covers all the key ideas without getting involved in the complications of more advanced systems. This book takes a...
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 ...
Rather, complications arise due to the fact that the object undergoes changes in pose relative to the viewing camera, changes in illumination relative to light sources, and may even become partially ...
Intelligent Robot What is known to ... when we rely on hormone to fight infection, cause many complications; when we eat sweet food to maintain blood glucose, the body's own blood sugar regulation abili
RFC3027:Protocol Complications with the IP Network Address Translator
If they were modified by someone, you would no longer have uniform applications of the logic, and that could lead to complications. Descriptions and explanations for each of the SFB/SFCs are ...
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
The complications stem due to the high level of integration, low power, and low cost requirements imposed on the chip manufacturers. Until recently, most designers and architects designed for one ...
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 ...