一旦按下WKInterfaceButton,我想显示一个加载视图(苹果提供的视图):

我需要这样做,因为在按下WKInterface按钮后,我正在调用主iPhone应用程序进行一些服务调用,这将需要一些时间来返回响应。
WKInterfaceController.openParentApplication(watchMessage, reply: { (reply:[NSObject : AnyObject]!, error: NSError!) -> Void in
Run Code Online (Sandbox Code Playgroud)
我使用WKInterfaceLabel的进度非常简单,
创建属性和出口,
@IBOutlet var loadingLabel: WKInterfaceLabel!
var loadingTimer = Timer()
var progressTracker = 1
Run Code Online (Sandbox Code Playgroud)
实施,
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)
}
Run Code Online (Sandbox Code Playgroud)
使用这些功能可以显示和隐藏,
startProgressIndicator()
stopProgressIndicator()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1982 次 |
| 最近记录: |