Я видел много уроков по созданию слайдов в меню, но они не работают. Уроки слишком старые.
Может кто-нибудь подсказать, как создать меню, которое выдвигается из нижней части экрана? В следующей ссылке вы можете увидеть пример изображения.
Слайд в меню снизу
Вот код, где я пытался это сделать:
var showAlertViewBtn: UIButton = {
let button = UIButton()
button.setTitle("Show", for: .normal)
button.backgroundColor = .blue
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: #selector(showAlertView), for: .touchUpOutside)
return button
}()
var customAlertView: UIView = {
let view = UIView()
view.backgroundColor = .white
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
var customAlertTextLabel: UILabel = {
let label = UILabel()
label.font = UIFont(name: "Ubuntu-Bold", size: 16)
label.text = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur"
label.textColor = .black
label.numberOfLines = 0
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
var customAlertBtn: UIButton = {
let button = UIButton()
button.setTitle("Cancel", for: .normal)
button.backgroundColor = .blue
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: #selector(customAlertBtnTapped), for: .touchUpOutside)
return button
}()
var customAlertViewBottomConstraint: NSLayoutConstraint!
@objc func customAlertBtnTapped() {
print("customAlertBtnTapped tapped")
self.customAlertViewBottomConstraint.constant = 400
}
@objc func showAlertView() {
UIView.animate(withDuration: 2.0) {
self.customAlertViewBottomConstraint.constant = 0
}
}
override func viewDidLoad() {
super.viewDidLoad()
setUpAlertView()
}
func setUpAlertView() {
view.addSubview(showAlertViewBtn)
showAlertViewBtn.heightAnchor.constraint(equalToConstant: 50).isActive = true
showAlertViewBtn.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
showAlertViewBtn.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
showAlertViewBtn.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
view.addSubview(customAlertView)
//customAlertView.frame = CGRect(x: 0, y: UIScreen.main.bounds.height, width: UIScreen.main.bounds.width, height: 400)
customAlertView.heightAnchor.constraint(equalToConstant: 400).isActive = true
customAlertView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
customAlertView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
customAlertViewBottomConstraint = view.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 400)
customAlertViewBottomConstraint.isActive = true
customAlertView.addSubview(customAlertTextLabel)
customAlertView.addSubview(customAlertBtn)
customAlertTextLabel.leftAnchor.constraint(equalTo: customAlertView.leftAnchor).isActive = true
customAlertTextLabel.rightAnchor.constraint(equalTo: customAlertView.rightAnchor).isActive = true
customAlertTextLabel.bottomAnchor.constraint(equalTo: customAlertBtn.topAnchor, constant: -20).isActive = true
customAlertBtn.leftAnchor.constraint(equalTo: customAlertView.leftAnchor).isActive = true
customAlertBtn.rightAnchor.constraint(equalTo: customAlertView.rightAnchor).isActive = true
customAlertBtn.heightAnchor.constraint(equalToConstant: 50).isActive = true
customAlertBtn.bottomAnchor.constraint(equalTo: customAlertView.bottomAnchor, constant: -40).isActive = true
}