Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在Swift 5中创建滑入菜单_Ios_Swift_Animation_Menu - Fatal编程技术网

Ios 如何在Swift 5中创建滑入菜单

Ios 如何在Swift 5中创建滑入菜单,ios,swift,animation,menu,Ios,Swift,Animation,Menu,我看过很多关于如何在菜单中创建幻灯片的教程,但它们都不起作用。教程太旧了 有人能告诉我如何创建从视图底部滑入的菜单吗?在下面的链接中,您可以看到一个示例图像 下面是我尝试执行此操作的一些代码: var showAlertViewBtn: UIButton = { let button = UIButton() button.setTitle("Show", for: .normal) button.backgroundColor = .blue button.tr

我看过很多关于如何在菜单中创建幻灯片的教程,但它们都不起作用。教程太旧了

有人能告诉我如何创建从视图底部滑入的菜单吗?在下面的链接中,您可以看到一个示例图像

下面是我尝试执行此操作的一些代码:

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

   }

这是我在菜单中的幻灯片中使用的代码

    func animateMenu(shouldExpand: Bool, completion: ((Bool) -> Void)? = nil) {
        if shouldExpand {
            UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .curveEaseInOut, animations: {
                self.homeController.view.frame.origin.x = self.xOrigin
                self.blackView.alpha = 1
            }, completion: nil)
        } else {
            self.blackView.alpha = 0
            UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .curveEaseInOut, animations: {
                self.homeController.view.frame.origin.x = 0
            }, completion: completion)
        }

        animateStatusBar()
    }

    func animateStatusBar() {
        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .curveEaseInOut, animations: {
            self.setNeedsStatusBarAppearanceUpdate()
        }, completion: nil)
    }

希望它能帮助你

向我展示你的尝试?@COVID19我在我尝试在菜单中播放幻灯片的地方添加了一些代码。你能帮帮我吗?代码部分起作用。未调用的customalertbtn的操作。我不明白为什么。也许你有比我的更好的解决方案或者一些技巧?谢谢你试着帮助我。这不是我的完美解决方案,但它对我有一点帮助。