我正在尝试在按下按钮时旋转 180 度并成像。现在我可以让它旋转 180,但是当我再次按下按钮时,图像不会旋转回来。我觉得我缺少一些简单的东西。
if 语句有效,我只是简化了代码,只留下了无效的部分。
if(self.dropdownConstraint.constant == -78)
{
//roate arrow up
UIView.animateWithDuration(0.5, animations: {
self.arrow.transform = CGAffineTransformMakeRotation((180.0 * CGFloat(M_PI)) / 180.0)
self.view.layoutIfNeeded()
})
}
else
{
//roate arrow down
UIView.animateWithDuration(0.5, animations: {
self.arrow.transform = CGAffineTransformMakeRotation((-180.0 * CGFloat(M_PI)) / -180.0)
self.view.layoutIfNeeded()
})
}
提前致谢!
最佳答案
变换不是累积的,因此第一个旋转 180 度(从 0 开始),第二个旋转 -180 度(也从零开始),两者看起来相同。只需修改反向变换以将旋转设置回零即可:
UIView.animateWithDuration(0.5, animations: {
self.arrow.transform = CGAffineTransformMakeRotation(0)
self.view.layoutIfNeeded()
})
关于ios - 按下按钮时旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32512843/