I am using SWRevealViewController library to make a slide out menu in swift, but I am struggling to put this menu in the right side. I have seen on the library description this comment
// Optional right view controller, can be nil if not used
@property (nonatomic) UIViewController *rightViewController;
but I am not familiar with objective C and I am not being able to do this on swift. This is a part of my code for the default(left) menu:
class ViewController: UIViewController, AVAudioPlayerDelegate {
@IBOutlet weak var playlistOutlet: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
playlistOutlet.target = self.revealViewController()
playlistOutlet.action = Selector("revealToggle:")
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
And revealViewController is called from the SWRevealViewController library
Swift 3
if revealViewController() != nil{
sideMenuBtn.target = revealViewController()
sideMenuBtn.action = #selector(SWRevealViewController.rightRevealToggle(_:))
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
Set the segue identifier value to sw_right instead of sw_rear
Better Alternative: https://github.com/jonkykong/SideMenu
Can you try this code:
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var sidemenuViewController = storyboard.instantiateViewControllerWithIdentifier("sideMenu") as! SideMenuViewController
sidemenuViewController.delegate = self
revealViewController().rightViewController = sidemenuViewController
revealViewController().delegate = self
sideMenuItem.target = self.revealViewController()
self.revealViewController().rightViewRevealWidth = self.view.frame.width * 0.8
sideMenuItem.action = Selector("rightRevealToggle:")
I followed this solution, in the controller of the front siding view use this:
override func viewDidLoad() {
super.viewDidLoad()
if self.revealViewController() != nil {
favoritesButton.target = self.revealViewController()
favoritesButton.action = "rightRevealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
Don't forget to create the Outlet to the item bar button first. In the storyboard, set the segue value to sw_right
And first that didn't work for me, but a clean helped.
Swift 4.1
private func setRightMenu(){
btnMenuright.addTarget(revealViewController(), action: #selector(SWRevealViewController.rightRevealToggle(_:)), for: UIControlEvents.touchUpInside)
}
I tried to do this when you want the sw_right show up. this code It worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With