简体   繁体   English

如何在按钮上单击不同的点来执行相同的动画

[英]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 ] 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. 如果仅移动框架,则不一定需要CGAffineTransformMakeTranslation。 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. 或者,而不是重置,您应该增加/减少值-30,而不是每次都使用相同的值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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