aryaxt / iOS-Slide-Menu

iOS Slide Menu with ability to add both left and right menu, and built in gesture recognizer. Similar to Path and Facebook
Other
1.53k stars 359 forks source link

Menu does not register touches when SlideMenu is not the root view controller #80

Open matthijn opened 9 years ago

matthijn commented 9 years ago

When I have a "loading" root view controller when the app starts which will determine to load either the slide menu controller or another controller, the menu does not work. It is visible, and the animations work just fine, only all touches are disabled.

I've distilled my setup to this:

In the app delegate

self.window.rootViewController = [[TestViewController alloc] init];

And in the testViewController viewDidAppear:

SlideNavigationController *slideNavigationController = [[SlideNavigationController alloc] initWithRootViewController:[[ARootViewController alloc] init]];
    slideNavigationController.leftMenu = [[UINavigationController alloc] initWithRootViewController:[[MenuViewController alloc] init]];
    slideNavigationController.menuRevealAnimator = [[SlideNavigationContorllerAnimatorScaleAndFade alloc] initWithMaximumFadeAlpha:0.6f fadeColor:[UIColor darkGrayColor] andMinimumScale:.8];
    slideNavigationController.enableSwipeGesture = NO;
    slideNavigationController.view.layer.shouldRasterize = NO;

    [self presentViewController:slideNavigationController: animated:YES callback:nil];

But then the menu does not respond to touches. If the slide navigation controller is the root view controller in the app delegate the menu does work correctly. It is really a matter of that the slide navigation controller must be the apps root controller. Is there a workaround or fix for this?

matthijn commented 9 years ago

Changing: SlideNavigationController.m line 575 to

    [self.view.superview insertSubview:menuViewController.view atIndex:0];

fixes the problem form me. It was

    [self.view.window insertSubview:menuViewController.view atIndex:0];
aryaxt commented 9 years ago

Oooh good point, I wrote the code assuming that SlideNavigationController will always be the rootViewController, will add this to the next version after iOS8 fix

Thanks

xScoobie commented 9 years ago

Hello, this is my first time writing on GitHub so I hope the following will be clear enough to understand.

So, I've been trying to implement the iOS Slide Menu into my application for a couple of hours now. I was trying to initialize the SlideNavigationController in my AppDelegate, but to no avail. Take note that I couldn't set SlideNavigationController to "Is Initial View Controller", because I had another ViewController prior to it. Enabling that option and everything worked flawlessly, though!

Anyway, I figured out that I didn't have to initialize the SlideNavigationController myself, because performing a show segue (push) from my ViewController to the SlideNavigationController would do that for me. (Yes, I'm quite new to xcode & objective-c :baby: ) Then, I proceeded by assigning a menu to the sharedInstance that was created. This took place in the prepareForSegue method and worked just fine.

However, as pretty the animations might be and I could see the items in the menu just fine, I couldn't click on any of them and it was mere functionless. So I tinkered around for a very long time till I figured out that the problem that got solved for someone above, actually caused a problem for me.

This: [self.view.superview insertSubview:menuViewController.view atIndex:0];

Was changed to: [self.view.window insertSubview:menuViewController.view atIndex:0];

Now, I'm not setting any of my ViewControllers to be the root view controller anywhere in my application. Although the storyboard might do that for us, but I'm not too sure. Reverting the "self.view.window" to "self.view.superview" solved my problem and now everything is working just fine!

I just wanted to leave this here for anyone who might possibly read this and is having the same headache as I do.

@aryaxt I might just be doing it the wrong way, but I felt like telling you about this "issue" anyway, incase you might know the depth of it. Thanks for all your work though! It's a great control nonetheless.

Greetings.

dileepfrog commented 9 years ago

@xScoobie Thanks for that explanation, I had exactly the same problem and you no doubt saved me hours of headache!

It seems like depending on your controller containment hierarchy either window or superview may be correct, so it should probably be configurable (or detected?)

aryaxt commented 9 years ago

@xScoobie Thanks for the info. This control was specifically made to be added to the main window as the root. Will look further into it and see if I can reproduce and get it to work when it's not the root

rfsbraz commented 9 years ago

Still reproducible in 1.4.6, @Matthijn solution fixed it for me.

eridbardhaj commented 9 years ago

Still this error persists. @Matthijn's solution fixed it for me too. This happened when I presented the SlideNavigationController from a viewController. When I set it as a rootViewController under AppDelegate it's ok

josemiguelgalvan commented 8 years ago

I had the same issue with didSelectRowAtIndexPath and no gestures received with the left menu. Thanks to @Matthijn answer is solved!

coolcool1994 commented 7 years ago

Today in June 2017 I tried implementing it and I utilized @Matthijn 's solution in this post. Why didn't developers here fix this already? This existed since THREE years ago. I use cocoa pod, and it sucks that I have to edit the cocoa pod directly.