对于搜索栏,我具有以下动画:
我的问题是,我不知道如何调整搜索栏的宽度以便将取消按钮对齐到左侧。
搜索栏作为子视图添加到父视图。我已经尝试设置其宽度锚点并更改其宽度(cardViewController.searchBar.frame.width
)-无论如何可能做错了事。
我的动画:
func animateTransitionIfNeeded(state: CardState, duration: TimeInterval) {
if runningAnimations.isEmpty {
let frameAnimator = UIViewPropertyAnimator(duration: duration, dampingRatio: 1) {
switch state {
case .expanded:
UIView.performWithoutAnimation {
self.backButton.alpha = 0
}
self.cardViewController.view.frame.origin.y = self.view.frame.height - self.cardHeight
UIView.animate(withDuration: 0.9, animations: {
self.cardViewController.searchBar.transform = CGAffineTransform(translationX: self.parentSearchVC.frame.origin.x - self.initialSearchBarPos, y: 0)
})
case .collapsed:
self.cardViewController.view.frame.origin.y = self.view.frame.height - self.cardHandleHeight
if self.backButton.alpha == 0 {
self.backButton.isHidden = false
UIView.animate(withDuration: 0.9, animations: {
self.backButton.alpha = 1
self.cardViewController.searchBar.transform = CGAffineTransform(translationX: 0, y: 0)
})
}
}
}
答案 0 :(得分:0)
最简单的解决方案是将UIStackView
与水平方向docs一起使用
isHidden
更改为箭头并取消视图isHidden
块内更改UIView.animateWithDuration
属性,例如:UIView.animateWithDuration(0.25) { () -> Void in
arrowButton.isHidden = !arrowButton.isHidden
cancelButton.isHidden = cancelButton.isHidden
}
您还可以使用动画更改视图之间的各种填充和分隔符。