idevelopper / pbrevealviewcontroller Goto Github PK
View Code? Open in Web Editor NEWA UIViewController subclass for revealing a left and/or right view controller above or below a main view controller.
License: MIT License
A UIViewController subclass for revealing a left and/or right view controller above or below a main view controller.
License: MIT License
Hi,
Is there any way to remove slidemenu after it pushed into some view controller?
So, here is my hierarchy
NavController > ViewController A > ViewController B
I have table on ViewController A (which is view controller that hold slide menu). On every cell I pressed, I push into View Controller B with
[self performSegueWithIdentifier:idmenu[indexPath.row] sender:self];
Its slidemenu still appear if we swipe from left, and I want to disable it. Is there any way to do it? Thank you!
Hi,
I'm trying to get the example project of this library to run. I downloaded the zip and ran pod install
inside the Example folder but it threw me this error.
Analyzing dependencies
Fetching podspec for `PBRevealViewController` from `../`
[!] The following pods are integrated into targets that do not have the same Swift version:
- PBRevealViewController required by PBRevealViewController_Example (Swift 3.0), Example3Swift (Swift 4.0), Example4Swift (Swift 3.0)
- PBRevealViewController/ObjC required by PBRevealViewController_Example (Swift 3.0), Example3Swift (Swift 4.0), Example4Swift (Swift 3.0)
My CocoaPods version is 1.2.1 and my Xcode is Xcode 9 beta 4.
Hi,
I have a setup like this.
From the green view controller, I want to switch to the pink view controller when the user taps on the white button in the green view controller.
I tried the following code but nothing happens.
guard let revealViewController = revealViewController() else { return }
let twoViewController = storyboard!.instantiateViewController(withIdentifier: "TwoViewController") as! TwoViewController
let navController = UINavigationController(rootViewController: twoViewController)
revealViewController.pushMainViewController(navController, animated: true)
Is there a different way to do this?
Added a demo project here as well.
Hi I'm having trouble with code:
if let indexPath = self.collectionView?.indexPathForItem(at: sender.location(in: self.collectionView)) {
let num = indexPath.last
if (imgBuddyArray[num!].nome) == "Aggiungi" {
print(imgBuddyArray[num!].nome)
**let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let desController = mainStoryboard.instantiateViewController(withIdentifier: "BuddyTableViewController") as! BuddyTableViewController
let newFrontViewController = UINavigationController.init(rootViewController:desController)
revealViewController()?.pushMainViewController(newFrontViewController, animated: true)**
}
} else {
}
This is for open BuddyTableViewController when I tapped un "Aggiungi"
This is BuddyTableViewController:
This VC is opened correctly from the right menu when I tapped on "Amici" using the same code above, but the first VC doesn'work
any suggest ?thanks
Hello.
Im changing my ViewController doing this :
let nc = UINavigationController(rootViewController: controller!)
revealViewController()?.setMainViewController(nc, animated: true)
Its working fine but my NavigationControllers (Name App Navigation Controller in picture) settings seems to get reset. At first launch the colors are correct. After swapping the ViewController with the code above everything is reset to standard. What happens to the NavigationController during changing ViewController? Im also no longer able to reach it from the ViewController after a swap
So : At first launch. "Dashboard Tab Controller"s NavigationBar looks correct and it can talk to "App Nav Controller".
After changing the ViewController NavigationBar is reset and I can no longer reach the "App Nav Controller"
The Swift version of this library is now on line!
Please feel free to PR, Fork, etc...
And please tell me when you use this controller in your project !
I am trying to find a way to delegate to the left view controller (menu) from the main view controller. Basically, my left menu has a menu option called "Refresh" in which, when clicked, I was hoping to dismiss the menu and call a "refresh" member within the main view controller that refreshes the data in the table view controller on that screen. I am sure there are other ways to do this that don't have to involve all this, but it seems the right place to put the option for my app. Is this possible?
Hi I'm starting with my new app for IOS in Swift and I'd like to use this Menu but there's something that doesn't work when I set this:
revealViewController()?.rightViewRevealWidth = CGFloat(Float(210))
If I use the default all works with right menu but if i try to change with a width doesn't work.
When the right menu is open if i click un HOME label the left VC didn't pushed on left and the left VC become Dark like in Picture.
As I said if I commented the row with CGFloat(Float(210) all works .
This is MainViewController :
class MainViewController: UIViewController {
@IBOutlet weak var rightButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
rightButton.target = self.revealViewController()
self.revealViewController()?.isRightPresentViewOnTop = false
revealViewController()?.rightViewRevealWidth = CGFloat(Float(210))
rightButton.action = #selector(PBRevealViewController.revealRightView)
if Reachability.isConnectedToNetwork(){
print("Internet Connection Available!")
}else{
Validator.Alert(title: "Attenzione!", message: "rete non disponibile", vc: self)
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Login")
self.present(viewController, animated: false, completion: nil)
}
}
and this MenuViewController:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let revealViewController:PBRevealViewController = self.revealViewController()!
let cell:MenuTableViewCell = tableView.cellForRow(at: indexPath) as! MenuTableViewCell
if cell.vociMenuLbl.text == "Home" {
let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let desController = mainStoryboard.instantiateViewController(withIdentifier: "MainViewController") as! MainViewController
let newFrontViewController = UINavigationController.init(rootViewController:desController)
revealViewController.setMainViewController(newFrontViewController, animated: true)
}
if cell.vociMenuLbl.text == "Profilo" {
let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let desController = mainStoryboard.instantiateViewController(withIdentifier: "ProfiloViewController") as! ProfiloViewController
let newFrontViewController = UINavigationController.init(rootViewController:desController)
revealViewController.pushMainViewController(newFrontViewController, animated: true)
}
if cell.vociMenuLbl.text == "Logout" {
let firebaseAuth = Auth.auth()
do {
try firebaseAuth.signOut()
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Login")
self.present(viewController, animated: false, completion: nil)
} catch let signOutError as NSError {
print ("Error signing out: \(signOutError)")
} catch {
print("Unknown error.")
}
}
}
As I said if I click "Home" this is the effect
Any suggest ?
thanks
@iDevelopper Can you please give sample code in swift 3 also with menu covering entire screen including top navigation bar and bottom tab bar?
i need the arrangement exactly like
https://github.com/John-Lluch/SWRevealViewController/files/275828/SWTabBarSwift2.zip
i want show viewcontrollers that are not in tapbar as a button (with tapbar in its footer,i mean whil e showing these vc's i want the bottom navigation bar in it also. ) as well as viewcontrollers in tabarcontroller also.
but i need that side menu over the viewcontroller.please help @iDevelopper
Here I am using swrevealViewController
to display side menu and here I am having tab bar items for view controllers and for this tab bar view controllers will have bar buttons and which will be having action for side menu and here if I select any of the bar buttons in tab bar which will opens side menu and will have access to another view controllers in side menu after going to any view controller then when I press the back button action was working fine for first time and when I move to another view controller in tab bar then also it works fine whenever I move to previous tab bar view controller and later i click side menu view controllers then the view controller was moving in the previous navigation view controller and in the navigation frontNVC
the last accessed new view controller was saving in navigation stack can you please help me how to resolve this ?
here is the code which used for moving side menu in did select row delegate method
if cell.titleCellLabel.text! == "Account"
{
var controller: UIViewController? = nil
let storyboard = UIStoryboard(name: "Main", bundle: nil)
controller = storyboard.instantiateViewController(withIdentifier: controllers[indexPath.row])
print(frontNVC?.viewControllers)
if controller != nil
{
// Prevent stacking the same controller multiple times
print(frontNVC)
_ = frontNVC?.popViewController(animated: false)
frontNVC?.viewControllers.removeAll()
// Prevent pushing twice FrontTableViewController
if !(controller is SWRevealViewController) {
// Show the controller with the front view controller's navigation controller
print(frontNVC)
frontNVC!.pushViewController(controller!, animated: false)
}
// Set front view controller's position to left
revealViewController().setFrontViewPosition(.left, animated: true)
}
}
Here I am using swrevealViewController to display side menu and here I am having tab bar for five view controllers and in this every view controller need to have bar button and which will be having action for side menu and here if I select any of the bar buttons in tab bar which will opens side menu and will have access to another view controllers in side menu after going to any view controller then when I press the back button action was working fine and when I move to another to another view controller in tab bar after coming back from view controller then also it works fine whenever I move to previous tab bar view controller and click side menu view controllers then the view controller was moving in the previous navigation controller and in the navigation frontNVC the last accessed new view controller was saving in navigation stack so if i select any view controller in side menu when tab item was in home then the view controller was displaying in last selected tab bar item view controller not in the home view controller and first time after running app it was working fine later not works and here i am using tab bar and side menu for displaying Please help me how to resolve this ?
here is the code which used for moving side menu in did select row delegate method
```
if cell.titleCellLabel.text! == "Account"
{
var controller: UIViewController? = nil
let storyboard = UIStoryboard(name: "Main", bundle: nil)
controller = storyboard.instantiateViewController(withIdentifier: controllers[indexPath.row])
print(frontNVC?.viewControllers)
if controller != nil
{
// Prevent stacking the same controller multiple times
print(frontNVC)
_ = frontNVC?.popViewController(animated: false)
frontNVC?.viewControllers.removeAll()
// Prevent pushing twice FrontTableViewController
if !(controller is SWRevealViewController) {
// Show the controller with the front view controller's navigation controller
print(frontNVC)
frontNVC!.pushViewController(controller!, animated: false)
}
// Set front view controller's position to left
revealViewController().setFrontViewPosition(.left, animated: true)
}
}
here is the code used for back button action used in side menu view controllers
@IBAction func backButtonAction(_ sender: Any) {
let nc = revealViewController().rearViewController as? UINavigationController
let frontNVC = (nc?.topViewController as? LeftSideViewController)?.frontNVC
_ = frontNVC?.popViewController(animated: true)
}
Here is my story board layout image shown below
![screen shot 2018-04-30 at 3 32 01 pm](https://user-images.githubusercontent.com/32094391/39427932-3fc48574-4ca3-11e8-83b3-f26dddd74f50.png)
i got it to work on my tvOS app , I used #if TARGET_OS_IOS for tvOS prohibited iOS properties , but It would be great if you added full support for tvOS , I'm sure many users would love to use this library on their tvOS apps , we could use the tv remote button 'Menu' to show and hide the RevealView.
Hi,
I used your PBRevealViewController to get the left and right menu. I am able to open the left and right menu's with drag. But it's not opening the menu when I tap the left and right bar buttons.
`
@IBOutlet var leftButton: UIBarButtonItem!
@IBOutlet var rightButton: UIBarButtonItem!
if self.revealViewController() != nil {
leftButton.target = self.revealViewController()
leftButton.action = "revealLeftView:"
self.revealViewController().leftPresentViewHierarchically = true
rightButton.target = self.revealViewController()
rightButton.action = #selector(PBRevealViewController.revealRightView)
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer)
}`
Above is the code i used and I checked with the example, there it is working but in program it is not working.
Please help me on this. Thank you!
Hi there,
In one of my viewControllers I use it with success, however I'm facing a problem in a viewController where I want the leftView to be called from a button. Whenever I try to set the delegate with self.revealViewController().delegate = self it fails at runtime caused by a nil. In my class I basically do this:
class MapViewController: UIViewController, PBRevealViewControllerDelegate {
...
@IBOutlet weak var menuButton: UIButton!
...
override func viewDidLoad() {
super.viewDidLoad()
...
self.revealViewController().delegate = self
...
menuButton.addTarget(self, action: #selector(self.revealLeftView), for: UIControlEvents.touchUpInside)
...
}
The self.revealLeftView basically just call the revealLeftView on the PBRevealViewController. I got my main view set up with pb_main and the menu view with pb_left.
If I leave out the delegate setting the menu works fine, but I can't customize it. Should I place the delegate in the ViewDidAppear instead?
Hi there, continuing from this thread. https://github.com/John-Lluch/SWRevealViewController/issues/612
Is it possible to get the RightView to stop by a tabBar? Minding that I just have the tabBar in the last controller, not in the navigationscontrollers before PBRevealViewController.
Hi,
Is there a way to disable opening the side menu by panning? I tried setting the property panFromLeftBorderWidth
to 0 but that didn't do anything.
Since I switched to this component my users reported that they can't delete anymore rows from the UITableView.
Is maybe related to the open menu gesture? How do I fix it?
Thanks
Hi there,
I'm used to using SWRevealViewController, and the way you get the front/main viewcontroller is:
let navController = self.revealViewController().frontViewController as? UINavigationController
mapViewController1 = navController!.topViewController as? MapViewController
However I can't this to work in PBRevealViewController, is there another way?
Update: I figured it out doing so:
let navController = self.revealViewController().mainViewController as? UINavigationController
mapViewController1 = (navController!.topViewController as? MapViewController)!
self.mapViewController1.forwardGeocodingTest()
But the rightview does not get unrevealed, can I do this?
is there way to remove panGestureRecognizer?
Hello ,
I am showing the mainVC progmatically after performing some code in the appdelegate file,
The problem that i don't have any initial view controller in the storyboard.
the problem here self.contentView?.addSubview(self.mainViewController!.view)
the mainViewController is nil, i try to set it progmatically in my "MainVC" that extends PBRevealViewController
but it seems that the loadView()
in the PBRevealViewController
start first.
Hi, first of all this is great library!
But I have one question regarding this implementation. So I created one project, and it has 3 menu item on its left menu controller. From each page on its menu, it has 3 button in bottom. See my picture
On didSelectRowAtIndexPath
's left menu table, I can "move" to 1,2, and 3 view controller by using
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
UIViewController *controller = [[UINavigationController alloc] initWithRootViewController:[storyboard instantiateViewControllerWithIdentifier:@"MyStoryboardViewController"]];
[self.revealViewController pushMainViewController:controller animated:YES];
On 1, 2, and 3 View Controller, I initialize hamburger menu on navigation item with this
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
UIImage *imgBtn = [UIImage imageNamed:@"menu"];
[barButton setImage:imgBtn];
barButton.target = self.revealViewController;
barButton.action = @selector(revealLeftView);
self.revealViewController.toggleAnimationType = PBRevealToggleAnimationTypePushSideView;
self.navigationItem.leftBarButtonItem = barButton;
And each view controller has custom UIView that consist of 3 button. It is like bottom tab bar on Spotify for iOS. It will navigate to A, B, and C view controller that has slidemenu button also.
Right now, I can navigate to A, B, and C by creating delegate on its custom view that require instance of destination UIViewController
as parameter so I can present that view controller using
[self presentViewController:vc animated:YES completion:nil];
But as the result, A, B, and C view controller can't initialize its slidemenu using code like on 1, 2, and 3 view controller. It hamburger menu is created, but it can't show slidemenu as it should be.
So where I did wrong here? I think my fault is on how to present A, B, and C view controller that use presentViewController
. Or another one? Any sugestion would be appreciated. Thank you so much!
I call [self.revealViewController setMainViewController:viewController animated:YES]; at the application start as it is belong on the business logic which controller should be root.
But as I see method for adding childViewController:
[self addChildViewController:toViewController];
is called only if mainViewController exists:
if (_mainViewController && animated) {
[self _swapFromViewController:_mainViewController toViewController:mainViewController operation:PBRevealControllerOperationReplaceMainController animated:animated];
}
It brakes my responder chain for actions handling in revealviewcontroller.
Im using pbreveal viewController to show side menu that comes over the bottom tab bar.Means,the side menu comes over the bottom bar and covers it. Now i want to present a new viewcontroller without hiding the bottom tab bar.
I mean i have 2 tabs.tab 1 and 2.On clicking a button in tab 1, i need to present a new vc that comes just above the bottom tabbar and covers vertically as usually presentation is going on. When im trying to do it,the new vc covers the entire screen.how can i begin the presention just above the tabbar .please help me
Hello,
If I tap outside of left view going to hide it and the finger lands on a button in main VC, the button triggers unwanted tap event. How to disable touch events in main VC until left view goes away?
i have implemented side menu using Objective C version
nothing happens when i click on side menu button
i have implemented using example from github
I'm using the latest Pod spec (1.2.3) in a Swift project. In this project i need just one main VC and a single side VC as menu.
In the storyboard set up the PBRVC to have only pb_main
and pb_left
set.
So far, so good: the app behaves as expected.
The problem appears when i try to transition from an orientation to another (say, portrait to landscape or viceversa, depending on the initial orientation of the device/simulator). On transition, i get a runtime error due to this forced unwrap:
To @iDevelopper: great work on this Swift reveal view controller. I tried many others (even with many more github stars) but this is simple, clear, efficient and really working out of the box without having to hack around too much
To those who need to have PBRVC working in a single side menu context anyway (say, a left menu), I did the following: a) setup a dummy reference to pb_right
and b) avoid the right side to appear when swiping from right to left, but only when the left side is not present (note: the right menu now show the same of the left side)
pb_right
to the same VC as pb_left
(so that the aforementioned unwrap wont be nil)PBRevealViewControllerDelegate
func revealController(_ revealController: PBRevealViewController,
shouldShowRight viewController: UIViewController) -> Bool {
return false
}
alpha
value) func revealController(_ revealController: PBRevealViewController, willShowLeft viewController: UIViewController) {
mainViewController?.view.isUserInteractionEnabled = false
mainViewController?.view.alpha = 0.75
}
func revealController(_ revealController: PBRevealViewController, willHideLeft viewController: UIViewController) {
mainViewController?.view.isUserInteractionEnabled = true
mainViewController?.view.alpha = 1
}
func revealControllerPanGestureShouldBegin(_ revealController: PBRevealViewController,
direction: PBRevealControllerPanDirection) -> Bool {
if mainViewController?.view.alpha == 1,
direction == .left {
return false
}
mainViewController?.view.alpha = 1
return true
}
Probably there could be other faster & dirtier ways, like just setting self.righViewRevealWidth = 0
Hi all,
I need to change the view controller programmatically from one screen to another, so far I tried these solutions:
NSNotification to the LeftViewController that tries a performSegueWithIdentifier
Instantiate UINavigationController with FirstViewController in my SecondViewController and
[self.revealViewController setMainViewController:navController]
Same as above but in LeftViewController
Same above but with pushMainViewController instead of setMainViewController
Also tried to call [self.revealViewController revealLeftView] before any of these methods
Hi bro i got these error when open example4Swift project bro .. Let to solve it let me know
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PBRevealViewController *Object;
Object=[[PBRevealViewController alloc] init];
PBRevealViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"new"];
[self.view addSubview:vc.view];
but gesture are not working only show view and side bar is not showing check my code and correct
In MainViewController for any push action I can easily call
self.navigationController?.pushViewController(UIViewController(), animated: true)
For changing mainViewController from menu then I can easily call
revealViewController().pushMainViewController(UIViewController(), animated:true)
But for some cases, I would like MainViewController to perform pushViewController from Left menu screen. Is it really possible with this library ? Or I should check other library ? This is currently main requirement for my project design :(
If I use storyboards everything works, if I instantiate it programmatically the controllers .revealViewController() is always nil and because of that it doesn't show the side controllers at all. Do I need to call something else after instantiation?
Repro:
Modify the Swift3 Example, at the bottom of "AppDelegate.swift" add these lines just before "return true":
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MainNC1") guard let finalVcLoggedIn = PBRevealViewController(leftViewController: UIViewController(), mainViewController: vc, rightViewController: UIViewController()) else { fatalError() } self.window?.rootViewController = finalVcLoggedIn self.window?.makeKeyAndVisible()
Go to the "Main.storyboard" file and change the main navigation controller identifier to "MainNC1".
Edit: The rest works correctly, if I save and instance of PBRevealViewController I can show and hide the side controllers, it's just the .revealViewController() that doesn't work.
How do I prohibit the menu from opening and/or closing using gestures? I basically want to disable them because they are interfering with my UITableViewController cell swiping gestures.
Hi Patric,
Can you make sample for side in menu that comes over "front/main view along with tab bar " with transparency ? It should be in objective c and storyboard with tab bar based application using PBRevealViewController library.
Thanks
I know this Class is not the same as swrevealviewcontroller but it is very similar , I'm transitioning from SWRevealviewcontroller, in my leftview i used to have a tableview customized with a gradient but when I started to use PBrevealviewcontroller the tableview background appears with white color and I also have an issue with the statusbar as I need it to show uistatusbarlightcontent(with SWRevealviewcontroller it used the statusbar from the viewcontroller) .
hi this is not an issue , this is a transition request
can you add one transition like this to the controller ?
https://github.com/microeditionbiz/Custom-Transition
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.