我正在尝试通过将约束设置为 0 或 100 来对 View 进行动画显示和出现。我遇到的问题是如何更改动画样式或方向?因为 View 将从下到上进行动画处理,但我想从上到下显示 View 。
我不能使用 self.view.layoutIfneeded ,因为我不希望它为整个 View 设置动画。我只想以正确的方向对特定 View 进行动画处理。谢谢。
UIView.animate(withDuration: 0.5, delay: 0, options: .allowUserInteraction, animations: {
//self.view.layoutIfNeeded()
self.topButtonView.layoutIfNeeded()
}, completion: nil)
最佳答案
使用CGAffineTransform
// move the view to top 100 offset from current y
self.topButtonView.transform = CGAffineTransform.identity.translatedBy(x: 0, y: -100)
// then reset the transform
// it will animate downward (back to it's original position)
UIView.animate(withDuration: 0.5, delay: 0, options: .allowUserInteraction, animations: {
self.topButtonView.transform = .identity
}, completion: nil)
关于ios - 使用所需的动画和方向对特定 View 进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51354145/