侧边菜单

时间:2019-03-05 16:55:35

标签: ios swift xcode side-menu

我正在使用SideMenu构建一个简单的视图。因此,如果我尝试单击它,则可以看到该选项,但侧面菜单是“所有项目下”而不是“所有项目下”。

这是ViewController的代码:

[代码] // // ViewController.swift // ArduinoHomeKit_bis // //由Michele Castriotta在17年4月20日创建。 //版权所有©2017 Michele Castriotta。版权所有。 //

导入UIKit 导入MessageUI

ViewController类:UIViewController,MFMessageComposeViewControllerDelegate {

@IBOutlet weak var leadingConstraint: NSLayoutConstraint!
var menuShowing = false

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib
    view.layer.shadowOpacity = 1
    view.layer.shadowRadius = 6
   // sendText()


    self.navigationController?.navigationBar.barStyle = UIBarStyle.blackTranslucent

    self.navigationController?.navigationBar.barTintColor =
        getUIColorFromRGBThreeIntegers(red: 41,green: 151,blue: 214);
    self.view.backgroundColor =  getUIColorFromRGBThreeIntegers(red: 41,green: 151,blue: 255);

    //self.view.backgroundColor = ColorLiteral
}

func getUIColorFromRGBThreeIntegers(red: Int, green: Int, blue: Int) -> UIColor {
    return UIColor(red: CGFloat(Float(red) / 255.0),
                   green: CGFloat(Float(green) / 255.0),
                   blue: CGFloat(Float(blue) / 255.0),
                   alpha: CGFloat(1.0))
}

func sendText() {
    if (MFMessageComposeViewController.canSendText()) {
        let controller = MFMessageComposeViewController()
        controller.body = ""
        controller.recipients = ["3400963483"]
        controller.messageComposeDelegate = self
        self.present(controller, animated: true, completion: nil)
    }
}

func messageComposeViewController(_ controller: MFMessageComposeViewController!, didFinishWith result: MessageComposeResult) {
    //... handle sms screen actions
    self.dismiss(animated: false, completion: nil)
}

override func viewWillDisappear(_ animated: Bool) {
    self.navigationController?.isNavigationBarHidden = false
}


@IBAction func openMenu(_ sender: Any) {
    if(menuShowing){
        leadingConstraint.constant = -150;
    }else{
        leadingConstraint.constant = 0;
        UIView.animate(withDuration: 0.3, animations: {
            self.view.layoutIfNeeded()
        })

    }
    menuShowing = !menuShowing
}

} [/ code]

这是输出视图:

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为问题可能是由于您首先添加了左侧菜单,然后添加了一些视图所致。您可以在最后添加menuView,也可以尝试将menuView放在最前面。将菜单转到IBOutlet,然后尝试以下代码:

[self.view bringSubviewToFront:menuView];