如何为 Apple Watch 添加加载视图? [英] How to add a loading view for apple watch?

查看:41
本文介绍了如何为 Apple Watch 添加加载视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在按下 WKInterfaceButton 后显示加载视图(由 Apple 提供的视图):

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

我需要这个,因为在按下 WKInterface 按钮后,我正在调用主 iPhone 应用程序来执行一些服务调用,这需要一些时间来返回响应.

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

推荐答案

我使用 WKInterfaceLabel 使用了非常简单的进度,

I have used very simple progress using WKInterfaceLabel,

创建属性和插座,

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

实施,

func startProgressIndicator() {
    // Reset progress and timer.
    progressTracker = 1
    loadingTimer.invalidate()

    // Schedule timer.
    loadingTimer = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(updateProgress), userInfo: nil, repeats: true)

    loadingLabel.setHidden(false)
}

@objc
private 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:
        break
    }
}

func stopProgressIndicator() {
    loadingTimer.invalidate()
    lastUpdateLabel.setHidden(true)
}

使用这些函数来显示和隐藏,

Use these functions to show and hide,

startProgressIndicator()
stopProgressIndicator()

这篇关于如何为 Apple Watch 添加加载视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆