今天整理一下在 Apple Watch 上實現(xiàn) Page 和 圓形進度條兩種效果,剛開始做的時候也很頭大,也沒見有多少人寫 特別是 關于 圓形進度條效果
的博客。其實這兩種效果實現(xiàn)起來超乎想象的簡單。
Page
實現(xiàn)Page效果有兩種方式:
第一種 在storyboard上連線
page_sb.png
第一個controller連第二個controller選擇next page
第二個controller連第三個controller選擇next page
他們之間的返回,SB也已經(jīng)為我們做好了
第二種 使用代碼
ExtensionDelegate
func applicationDidFinishLaunching() {
// Perform any final initialization of your application.
WKInterfaceController.reloadRootControllers(withNames: ["Controller1",
"Controller2",
"Controller3"],
contexts: nil)
}
如果說我想讓Page中的第一個controller的按鈕操作影響第二個controller,我目前找到的方法是 notification
圓形進度條
當時為了這個東西也是翻遍的了 度娘
后來還是在stackoverflow上找到一個答案。 WKImageAnimatable
協(xié)議的有一個函數(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)
類似 UIImageView
的 startAnimating() 方法,看到這里明眼人就明白了,watch上實現(xiàn)的進度條是一張圖片,進度的改變的過程就是一組幀動畫你要做的就是算好執(zhí)行到哪一幀
實現(xiàn)進度條用到的圖片已經(jīng)有大大們制作好了工具傳送門