How to navigate to different storyboards along with sidemenu in swift 3

最后都变了- 提交于 2019-12-06 05:40:23

here is code open side from other storyboard

 @IBAction func menutapped(_ sender: Any) {

        var appdelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
        appdelegate.centerContainer?.toggle(MMDrawerSide.left, animated: true, completion: nil)


    }

Main View Controller

import UIKit

class ViewController: UIViewController , UICollectionViewDelegate , UICollectionViewDataSource , UIGestureRecognizerDelegate {

    @IBOutlet weak var collectioncell: UICollectionView!
    var objectProfile:SideMenuViewController!
    var tapGesture = UITapGestureRecognizer()

       override func viewDidLoad() {

        super.viewDidLoad()


        tapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.myviewTapped(_:)))
        tapGesture.numberOfTapsRequired = 1
        tapGesture.numberOfTouchesRequired = 1
        collectioncell.addGestureRecognizer(tapGesture)
        collectioncell.isUserInteractionEnabled = true
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        self.objectProfile = storyboard.instantiateViewController(withIdentifier: "SideMenuViewController") as! SideMenuViewController

        self.objectProfile.view.frame = CGRect(x:  -(self.view.frame.size.width - 40), y: 0, width: self.view.frame.size.width - 40, height: self.view.frame.size.height)
        self.view.addSubview(self.objectProfile.view)
        self.navigationController?.didMove(toParentViewController: self.objectProfile)

        self.collectioncell.layer.cornerRadius = 5.0
        self.collectioncell.layer.borderWidth = 5.0
        self.collectioncell.clipsToBounds = true
        self.collectioncell.layer.borderColor = UIColor.clear.cgColor
        self.collectioncell.layer.masksToBounds = true


    }
    func myviewTapped(_ sender: UITapGestureRecognizer) {

        if self.objectProfile.view.isHidden == false {
            UIView.animate(withDuration: 0.3)
            {
                self.objectProfile.view.frame = CGRect(x:  -(self.view.frame.size.width - 90), y: 0, width: self.view.frame.size.width - 90, height: self.view.frame.size.height)
            }
        }
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    @IBAction func Mrnupressed(_ sender: UIBarButtonItem) {
        UIView.animate(withDuration: 0.3)
        {
            self.objectProfile.view.frame = CGRect(x: 0  , y: 0, width: (self.view.frame.size.width - 100), height: self.view.frame.size.height)
        }

    }


    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
    {
        return 6
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
    {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath) as! MainCollectionViewCell
        return cell
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {

        let cellsize = CGSize(width: (collectioncell.bounds.size.width/2) - 12, height:(collectioncell.bounds.size.height/3) - 20)

        return cellsize
    }






}

Child View Controller

import UIKit

class SideMenuViewController: UIViewController,UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var sidemenutable: UITableView!
    var stri:String!
    var ArrarMenu:[String] = ["Home","SiteMep","Student","About Us","Help"]
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return ArrarMenu.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SideMenuCell") as! SideMenuTableViewCell
        let objarray = ArrarMenu[indexPath.row]
        cell.lblitem.text = objarray
        stri = objarray
        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        if indexPath.row == 0{
            self.performSegue(withIdentifier: "SegueForHome", sender: self)
        }
    }

}

In This Code I Am use Child View As Side Manu Controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!