我试图通过更改NSLayoutConstriant的常量来在屏幕上移动UIView。 UIView移动但在移动时没有动画。
初始约束
func setUpView(){
cont = OverlayController()
let overlay = (cont?.view!)!
gameView.addSubview(overlay)
top = overlay.topAnchor.constraint(equalTo: gameView.bottomAnchor, constant: -175)
centerX = overlay.centerXAnchor.constraint(equalTo: gameView.centerXAnchor)
width = overlay.widthAnchor.constraint(equalToConstant: gameView.frame.width * 0.7)
height = overlay.heightAnchor.constraint(equalToConstant: gameView.frame.width * 0.7)
centerY = overlay.centerYAnchor.constraint(equalTo: gameView.centerYAnchor)
top?.isActive = true
centerX?.isActive = true
width?.isActive = true
height?.isActive = true
let swipeListener = UISwipeGestureRecognizer(target: self, action: #selector(swiped))
swipeListener.direction = .up
overlay.addGestureRecognizer(swipeListener)
}
动画方法(向上轻扫)
func animate(){
centered = !centered
cont?.view.layoutIfNeeded()
self.top?.constant = -500
UIView.animate(withDuration: 3) {
self.cont?.view.layoutIfNeeded()
}
}
我如何得到它,以便动画的UIView在移动时会动画?
答案 0 :(得分:1)
您需要重新布局超级视图
+----+-----------------------------------------------------------------------------------+----+
|col1|col2 |col3|
+----+-----------------------------------------------------------------------------------+----+
|152 | XXXXXXXXXX XXXXXXXXXX.1001 0503~ADX\|0\|ZZ~NTE\|ADD\|XXXXXXXXXX/~SE\|40\|0060~GE\|| |
+----+-----------------------------------------------------------------------------------+----+