Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when using PBRVC in single side view context (i.e. a single left side menu) #32

Closed
pgmassari opened this issue Sep 7, 2017 · 5 comments

Comments

@pgmassari
Copy link

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:

frame = (self.rightViewController?.view.frame)!

Possibly some other lines might cause unwrap problems too (although, I've been heavily using it with no other kinds of crash)

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)

  1. in storyboard, set pb_right to the same VC as pb_left (so that the aforementioned unwrap wont be nil)
  2. subclass PBRVC and make it a PBRevealViewControllerDelegate
  3. stop this:
 func revealController(_ revealController: PBRevealViewController,
                        shouldShowRight viewController: UIViewController) -> Bool {
    return false
  }
  1. also, you'll need something to keep track that the left side is open (i use my MVC 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
  }
  1. disable the swipe right to left to avoid the right side to come in (but keep it close the left side anyway)
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

iDevelopper added a commit that referenced this issue Sep 8, 2017
@iDevelopper
Copy link
Owner

Hi @pgmassari , thanks a lot for revealing this issue and for your great comment!

Fixed in 1.2.4

@pgmassari
Copy link
Author

Thanks @iDevelopper for the fast fix.

Very good: confirmed working in 1.2.4, with just pb_main and pb_left set, while pb_right is not set.

No subclassing of PBRVC is necessary, unless customization is needed (i.e. leftViewRevealWidth or leftViewBlurEffectStyle in its viewDidLoad, ...)

@iDevelopper
Copy link
Owner

I like subclassing for the delegate functions but they should be in AppDelegate or elsewhere... Properties for customisation can be set in the main view controller also.

@pgmassari
Copy link
Author

I'm fairly new to iOS development... is there a specific reason on why the delegate method should be in the AppDelegate class?

I liked the idea of having the "reveal vc stuff" in a respective subclass.

@iDevelopper
Copy link
Owner

No reason, but you said "No subclassing of PBRVC is necessary". I personally like subclassing my PBRevealViewController Class. All customisations and delegate implementations can be done in this subclass in rapport. (Note that you cannot subclass a Swift Class in Objective-C, for developers working in Objective-C and using Swift libairies).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants