【发布时间】:2020-07-10 15:02:41
【问题描述】:
我实际上已经完成了当底部表弹出时它从底部到顶部动画并且背景颜色会淡入的一半部分,但是当我想关闭底部表时,它的不同情况,背景动画不这样做褪色出动画,而不是做从上到下的动画,有人知道我为什么会得到这个错误吗?
这是我的代码
let fullView: CGFloat = 0
let screenSize: CGRect = UIScreen.main.bounds
@IBOutlet weak var Text: UILabel!
@IBOutlet weak var topView: UIView!
@IBOutlet weak var vieww: UIView!
@IBOutlet weak var botView: UIView!
@IBOutlet weak var Button: UIButton!
@objc func pressed(sender : Any) {
var closeView = screenSize.height
print(closeView)
UIView.animate(withDuration: 0.4) { [weak self] in
let frame = self?.view.frame
self?.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
self?.view.frame = CGRect(x: 0, y: closeView, width: frame!.width, height: frame!.height)
}
UIView.animate(withDuration: 0.4, delay: 0.35, options: .curveEaseOut, animations: {
self.topView.alpha = 0.0
}, completion: nil)
isShown = false
}
override func viewDidLoad() {
super.viewDidLoad()
button()
self.topView.alpha = 0.0
vieww.layer.cornerRadius = 20
vieww.layer.borderWidth = 0.5
vieww.layer.borderColor = UIColor(red:222/255, green:225/255, blue:227/255, alpha: 1).cgColor
vieww.clipsToBounds = true
botView.layer.masksToBounds = false
botView.layer.shadowColor = UIColor.black.cgColor
botView.layer.shadowOpacity = 0.14
botView.layer.shadowOffset = CGSize(width: 0, height: 0)
botView.layer.shadowRadius = 2.7
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
//when the animation is popping up
UIView.animate(withDuration: 0.4) { [weak self] in
let frame = self?.view.frame
// let yComponent = UIScreen.main.bounds.height - 896
let yComponent = self?.fullView
self?.view.frame = CGRect(x: 0, y: yComponent!, width: frame!.width, height: frame!.height)
}
UIView.animate(withDuration: 0.4, delay: 0.35, options: .curveEaseOut, animations: {
self.topView.alpha = 0.5
}, completion: nil)
}
func button() {
Button.addTarget(self, action: #selector(pressed), for: .touchUpInside)
}
我仍然不知道为什么会发生这种情况,我猜测它是因为关闭动画和淡出动画不会做任何事情,因为首先调用关闭动画......但它仍然没有任何意义,因为那时我尝试在底部工作表中弹出它的工作,现在我尝试使用相同的方法但它不工作......知道吗?谢谢:)
【问题讨论】:
-
isShown是什么? -
你能分享一下XIB部分吗?
-
@ShashankMishra 好的等等先生
-
@jawadAli isShown 是一个变量,我用来弹出和关闭底部表,因为如果我不使用底部表可能会弹出多次,具体取决于您单击按钮的次数,我使用 isShow 来防止这种情况发生
-
self.topView 在哪里解散?请显示该代码
标签: ios swift animation uiview background