美文网首页
watchOS 2 第二章:Architecture

watchOS 2 第二章:Architecture

作者: V_coa | 来源:发表于2015-10-20 17:44 被阅读74次

Operating system

在Apple Watch中运行的是watch OS。它是建立在iOS上的,但是这些内容不是在本书的范围内。

Introducing WatchKit

What it is

•WKInterfaceController:这是WatchKit版本的一个UIViewController,后面我们将会使用到它
•WKInterfaceObject:这是最基础的一个类,所有Watch Interface的元素都继承它,如buttons和labels等
•WKInterfaceDevice:这个类提供一些watch的信息,如watch的屏幕的大小

WKInterfaceController

Lifecycle

•awakeWithContext(:):在WKInterfaceController从sb加载的时候调用
•willActivate():这个方法类似于iOS的UIViewController中得viewWillAppear(
:),view将要出现的时候调用。
•didDeactivate():这个方法和iOS中的UIViewController的viewDidAppear(_:)类似。

Segues

在iOS中也有Segues,但是在WatchKit有些不同,在WatchKit中提供了一些方便的方法给我们使用。
•contextForSegueWithIdentifier(:)这个方法放回一个AnyObject类型的对象,可以用于我们在controller之间传值
•awkeWithContext(
:)这个方法在WKInterfaceController在sb中加载时调用,这个方法接收到上面的contextForSegueWithIdentifier(_:)return的object

Interface objects

在WatchKit中和UI相关的类只有11个,没有iOS那么多,它们大多继承自WKInterfaceObject,并不像UIKit那样继承自UIView,UIControl等等。

WatchKit view and controls

WKInterfaceObject在你的界面上,你并不会用到它,大多用到它的子类
WKInterfaceButton
WKInterfaceDate
WKInterfaceGroup
WKInterfaceImage
WKInterfaceLabel
WKInterfaceMap
WKInterfaceSeparator
WKInterfaceSlider
WKInterfaceSwitch
WKInterfaceTable
WKInterfaceTimer
WKInterfaceMovie
WKInterfacePicker

相关文章

网友评论

      本文标题:watchOS 2 第二章:Architecture

      本文链接:https://www.haomeiwen.com/subject/htmzcttx.html