gpt4 book ai didi

ios - 更改添加为 subview 的搜索栏的宽度

转载 作者:行者123 更新时间:2023-11-29 05:42:33 27 4
gpt4 key购买 nike

我的搜索栏具有以下动画:

search bar

我的问题是,我不知道如何调整搜索栏的宽度以使“取消”按钮向左对齐。

搜索栏将作为子视图添加到父视图。我已经尝试设置其宽度锚点并更改其宽度(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)
})

}
}
}

最佳答案

最简单的解决方案是将UIStackView与水平方向docs一起使用


将视图添加到UIStackView
isHidden更改为箭头并取消视图
如果要动画,可以在isHidden块内更改UIView.animateWithDuration属性,例如:


UIView.animateWithDuration(0.25) { () -> Void in
arrowButton.isHidden = !arrowButton.isHidden
cancelButton.isHidden = cancelButton.isHidden
}


您还可以使用动画更改视图之间的各种填充和分隔符。

关于ios - 更改添加为 subview 的搜索栏的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56434266/

27 4 0