今天整理一下在 Apple Watch 上實(shí)現(xiàn) Page 和 圓形進(jìn)度條兩種效果,剛開(kāi)始做的時(shí)候也很頭大,也沒(méi)見(jiàn)有多少人寫(xiě) 特別是 關(guān)于 圓形進(jìn)度條效果
的博客。其實(shí)這兩種效果實(shí)現(xiàn)起來(lái)超乎想象的簡(jiǎn)單。
Page
實(shí)現(xiàn)Page效果有兩種方式:
第一種 在storyboard上連線
page_sb.png
第一個(gè)controller連第二個(gè)controller選擇next page
第二個(gè)controller連第三個(gè)controller選擇next page
他們之間的返回,SB也已經(jīng)為我們做好了
第二種 使用代碼
ExtensionDelegate
func applicationDidFinishLaunching() {
// Perform any final initialization of your application.
WKInterfaceController.reloadRootControllers(withNames: ["Controller1",
"Controller2",
"Controller3"],
contexts: nil)
}
如果說(shuō)我想讓Page中的第一個(gè)controller的按鈕操作影響第二個(gè)controller,我目前找到的方法是 notification
圓形進(jìn)度條
當(dāng)時(shí)為了這個(gè)東西也是翻遍的了 度娘
后來(lái)還是在stackoverflow上找到一個(gè)答案。 WKImageAnimatable
協(xié)議的有一個(gè)函數(shù):
// Play a subset of images for a certain number of times. 0 means repeat until stop.
public func startAnimatingWithImages(in imageRange: NSRange, duration: TimeInterval, repeatCount: Int)
類(lèi)似 UIImageView
的 startAnimating() 方法,看到這里明眼人就明白了,watch上實(shí)現(xiàn)的進(jìn)度條是一張圖片,進(jìn)度的改變的過(guò)程就是一組幀動(dòng)畫(huà)你要做的就是算好執(zhí)行到哪一幀
實(shí)現(xiàn)進(jìn)度條用到的圖片已經(jīng)有大大們制作好了工具傳送門(mén)