Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate WKInterfaceLabel with text change apple watch swift

I am working on an apple watch application. In the application, I have a view where the user may swipe left and right between 3 given results. I am using WKInterfaceLabel to show result information. On each swipe, labels are updated with new text.

View screenshot:

Results screen

I want to animate the change of text on swipe. How can I do this?

Any help provided will be appreciated. Thanks!

like image 410
Akshay Sunderwani Avatar asked Sep 13 '17 04:09

Akshay Sunderwani


1 Answers

This is not very elegant, but it should work:
You can fade out the contents of a WKInterfaceLabel, and fade in another label in its place. So, place 2 WKInterfaceLabel objects at the same place. One of them is visible (alpha = 1.0) and the other invisible (alpha = 0.0).
When you swipe, determine the new value that should be shown, and set it to the invisible label.
Then, animate the transition using the function animate(withDuration:animations:) of the WKInterfaceController. In the animation block, change the alpha values as required, something like

animateWithDuration(1.0) {
    self.visibleLabel.setAlpha(0.0)
    self.invisibleLabel.setAlpha(1.0)
}  

Hope this helps!

like image 177
Reinhard Männer Avatar answered Sep 28 '22 12:09

Reinhard Männer