Animate WKInterfaceLabel with text change apple watch swift

1.5k Views Asked by At

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!

2

There are 2 best solutions below

4
On

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!

1
On

try:-

 func labelimage(img: UIImageView) {
        print(labelrate.hidden)
        if (labelrate.hidden) {
            UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
                self.labelrate.alpha = 1
            }, completion: nil)
        }
        else {
            UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
                self.labelrate.alpha = 0
            }, completion: nil)
        }
        self.labelrate.hidden = !self.labelrate.hidden
    }