gpt4 book ai didi

ios - 如何使用 Swift 从右到左和从左到右设置自定义 View 的动画

转载 作者:行者123 更新时间:2023-11-30 12:14:47 25 4
gpt4 key购买 nike

我设计了一个 View 。通常,当我单击按钮时,此 View 将显示和隐藏。现在我正在尝试从左到右和从右到左为该 View 设置动画。下面是我的代码,但它不起作用。请检查一下。

if(self.openedView) {
self.openedView = false;
UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseIn, animations: {() -> Void in



}, completion: {(_ finished: Bool) -> Void in
})

shareMainView.isHidden = true;
} else {
self.openedView = true;
UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut, animations: {() -> Void in
}, completion: {(_ finished: Bool) -> Void in
/*done*/
})

shareMainView.isHidden = false;
}

shareMainView.isHidden = false;这是我的 View ,它将随动画打开和隐藏。

最佳答案

extension UIView {
func comingFromRight(containerView: UIView) {
let offset = CGPoint(x: containerView.frame.maxX, y: 0)
let x: CGFloat = 0, y: CGFloat = 0
self.transform = CGAffineTransform(translationX: offset.x + x, y: offset.y + y)
self.isHidden = false
UIView.animate(
withDuration: 1, delay: 0, usingSpringWithDamping: 0.47, initialSpringVelocity: 3,
options: .curveEaseOut, animations: {
self.transform = .identity
self.alpha = 1
})

} }

您可以像这样使用它:

anyView.comingFromRight(containerView: anyView.superview)

关于ios - 如何使用 Swift 从右到左和从左到右设置自定义 View 的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45566520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com