Search code examples
iosswiftanimationibaction

how to perform same animation with different points on button click ios Swift


i am trying to increase the temperature with animation on button click it is working when i tap the button first time but when i tap the button again nothing happens. I am using a image view (red color) for showing the temperature here is my code that i am using behind action this is my meter[![][1]]2

        UIView.animateWithDuration(3.0, animations: {

        self.progress.transform =  CGAffineTransformMakeTranslation((self.progress.frame.origin.x -self.progress.frame.origin.x ), -30)
    })

it should increase each time i click the + button but its not happening can anyone explain what is the issue ?


Solution

  • To move your image you should do a concatenation of your transformations

    UIView.animateWithDuration(3.0, animations: {
    
       let transform =  CGAffineTransformMakeTranslation(0, -30)
       self.progress.transform = CGAffineTransformConcat(self.progress.transform, transform)
    })