7

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!

Akshay Sunderwani
  • 12,084
  • 8
  • 26
  • 52

2 Answers2

2

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!

Reinhard Männer
  • 11,202
  • 4
  • 45
  • 85
0

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
    }
Jayprakash Singh
  • 1,199
  • 2
  • 11
  • 26
  • 1
    I am doing this work in watchOS and uiimageview and uiview are not available in watchOS. Can you provide any other solution? Also, what is labelrate? And why are you passing img in function? – Akshay Sunderwani Sep 22 '17 at 11:39