简体   繁体   中英

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 这是我的仪表[![] [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 ?

CGAffineTransformMakeTranslation is not necessarily needed if only moving the frame. The same could be done simply by setting a new frame to the view. Also, if you don't reset the transformation anywhere there is nothing to animate in the second time. Or instead of resetting, you should increment/decrement the value -30, not use the same value every time.

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)
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM