【发布时间】:2020-06-29 05:17:05
【问题描述】:
每当我按下添加按钮时,我希望下拉视图从黑色视图下方滑动,而不是显示在顶部然后向下滑动。
我曾经在故事板中使用黑色视图,它停留在下拉视图的前面,从而产生从黑色视图下方滑动的效果。现在我在情节提要中删除了该视图并以编程方式创建了一个新视图,但我遇到了这个问题。
我尝试了常用的方法bringToFront/sendToBack,但是没有用。
这是我的代码
override func viewDidLoad() {
super.viewDidLoad()
blackView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 500, height: 100))
blackView.backgroundColor = UIColor.black
self.view.addSubview(blackView)
self.view.bringSubviewToFront(blackView)
blackView.layer.zPosition = .greatestFiniteMagnitude
self.view.sendSubviewToBack(dropDownView)
dropDownView.isHidden = true
addButton.setImage(#imageLiteral(resourceName: "addBa"), for: .normal)
addButton.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
self.blackView.addSubview(addButton)
}
@objc func buttonAction() {
if (dropDownView.isHidden == true ) {
openDropDownView()
}
else { closeDropDownViewA() }
}
func openDropDownView() {
self.dropDownView.isHidden = false
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseOut, animations: {
var fabricTopFrame = self.dropDownView.frame
fabricTopFrame.origin.y -= fabricTopFrame.size.height
var fabricBottomFrame = self.dropDownView.frame
fabricBottomFrame.origin.y += fabricBottomFrame.size.height
self.dropDownView.frame = fabricTopFrame
self.dropDownView.frame = fabricBottomFrame
UIView.animate(withDuration: 0.5) {
self.dimView.alpha = 0.75
}
}, completion: { finished in
print("dropDownView opened!")
})
}
谢谢!
【问题讨论】:
-
openDropDownView看起来如何? -
@GabrielPires 我更新了!谢谢