How to add a loading view for apple watch?

匿名 (未验证) 提交于 2019-12-03 10:09:14

问题:

I want to display a loading view (the one provided by apple) once a WKInterfaceButton is pressed:

I need this because after the WKInterfacebutton is pressed, I'm calling the main iPhone app to do some service calls which will take some time to return a response.

    WKInterfaceController.openParentApplication(watchMessage, reply: { (reply:[NSObject : AnyObject]!, error: NSError!) -> Void in

回答1:

I have used very simple progress using WKInterfaceLabel,

Create properties and outlets,

@IBOutlet var loadingLabel: WKInterfaceLabel! var loadingTimer = Timer() var progressTracker = 1

Implementation,

func startProgressIndicator() {      // reset progress and timer     progressTracker = 1     loadingTimer.invalidate()      // schedule timer     loadingTimer = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(InterfaceController.updateProgress), userInfo: nil, repeats: true)      loadingLabel.setHidden(false) }  func updateProgress() {      switch progressTracker {     case 1:         lastUpdateLabel.setText("Loading..")         progressTracker = 2;     case 2:         lastUpdateLabel.setText("Loading...")         progressTracker = 3;     case 3:         lastUpdateLabel.setText("Loading.")         progressTracker = 1;     default:         print("default case")     } }  func stopProgressIndicator() {      loadingTimer.invalidate()     lastUpdateLabel.setHidden(true) }

Use these functions to show and hide,

startProgressIndicator() stopProgressIndicator()


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!