How to Add a Loading View for Apple Watch

How to add a loading view for apple watch?

I have used very simple progress using WKInterfaceLabel,

Create properties and outlets,

@IBOutlet private var loadingLabel: WKInterfaceLabel!
private var loadingTimer = Timer()
private 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(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()

Is there an ActivityIndicator in WatchKit for Apple Watch?

Edit: This answer was originally posted prior to the introduction of Apple Watch models with cellular and wifi connectivity, and thus may no longer apply on newer models of the device (considering significant performance improvements).


This thread on the Apple Developer forums has an authoritative answer from an Apple engineer about why you shouldn't be performing network operations with Apple Watch.

There are two big reasons not to perform networking operations from your watch app / extension:

  1. Users are interacting with their watches for only a brief period of time. See the Human Interface guidelines on this one.

    If you measure interactions with your iOS app in minutes, you can expect interactions with your WatchKit app to be measured in seconds. So interactions should be brief and interfaces should be simple.

  2. The system may deadlock if the network request does not complete.

    Our recommendation is that, in general, you should not perform complex networking operations inside a WatchKit Extension...

    [Apple recommends that developers] have a single process that is in charge of updating the information in your database (likely your iOS app), and then your extensions would have (essentially) read-only access to this [cached] database....


That being said. If you really need a UIActivityIndicator, rdar://19363748 (I don't think this one has been open radar-ed yet), developers have already filed requests for official support.

You can create a series of images in the activity indicator style of your choice and then animate them using the startAnimatingWithImagesInRange:duration:repeatCount: API. See Apple's Lister app for an example of wkinterfaceimage animation.

Alternatively, look here for a WatchKit Animation tutorial and included "spinner" graphics.

Custom branding on watch load screen

After extensively double-checking, I can confirm there isn't currently a way to add it using the SDK. I suspect the Watch displays things slightly differently in the shipping OS or they were presenting using an old version.

Could the screen of apple watch be scrolling/paging style?

Yes. It does. WKInterface allows you to scroll to bottom/up when content is more than the screen size. As you keep on adding the content to interface, Watchkit will automatically create scroll that allows you to view the content to the bottom. Second one is horizontal scrolling page by page. In WatchKit there is only one way to do horizontal page based scrolling. You have to set up a page based UI. You will have to have a new instance of a controller for each page. See link for more info.

How do you add a pulldown to refresh feature on a Apple Watch using Swift

This is not possible in the WatchKit SDK. There is no access to anything similar to the UIRefreshControl from iOS for third party developers, and additionally nothing equivalent to UIGestureRecognisers nor API functions associated with taps or swiping for third party developers.

With regards to taps, it is possible to respond to events on button presses, through an IBAction, it's just that we can't interrogate the taps in terms of things like tap location...



Related Topics



Leave a reply



Submit