Search code examples
cocoa-touchuisplitviewcontrollergesture

how to remove splitviewcontroller's gesture iOS7


I have a splitView Controller which opens/hides a menu by default with a gesture

enter image description here enter image description here

it is a good idea to have it without coding anything, but as you see I added a carousel which works with that gesture, but the split menu's gesture disabled carousel mobility, this is my code for getting UISplitViewController:

CODE FOR DISPLAYING THE SPLIT VIEW CONTROLLER


InitialVC.m:

-(void)viewDidAppear:(BOOL)animated{
    UIStoryboard *storyBoard        = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];

    if ([[[UIDevice currentDevice]model] hasPrefix:@"iPad"]){
        ViewController    *rightViewController       = [storyBoard instantiateViewControllerWithIdentifier:@"ViewController"];
        rightViewController.navigationItem.titleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
        [functions showSplitViewControllerInView:self.view withDetailViewController:rightViewController];
    }
}

Functions.m:

-(void)showSplitViewControllerInView:(UIView *)view
            withDetailViewController:(id)rightViewController{

    UIStoryboard *mainStoryboard        = [UIStoryboard storyboardWithName:@"iPad" bundle: nil];

    UINavigationController  *leftNavController;
    UINavigationController  *rightNavController;

    MenuPrincipalVC  *leftViewController     = [mainStoryboard instantiateViewControllerWithIdentifier:@"MenuPrincipalVC"];

    leftNavController                   = [[UINavigationController alloc] initWithRootViewController:leftViewController];
    rightNavController                  = [[UINavigationController alloc] initWithRootViewController:rightViewController];

    leftNavController.toolbarHidden                 = FALSE;
    rightNavController.toolbarHidden                = FALSE;
    leftNavController.navigationBar.translucent     = TRUE;
    rightNavController.navigationBar.translucent    = TRUE;
    leftNavController.toolbar.translucent           = FALSE;
    rightNavController.toolbar.translucent          = TRUE;

    UISplitViewController   *splitViewController    = [[UISplitViewController alloc] init];
    splitViewController.viewControllers             = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];
    splitViewController.delegate        = rightViewController;

    view.window.rootViewController      = splitViewController;
}

CODE FOR SHOWING/HIDDING BUTTON MENU ON DETAIL VIEW CONTROLLER

ViewController.m:

#pragma mark - UISplitViewDelegate methods
-(void)splitViewController:(UISplitViewController *)svc
    willHideViewController:(UIViewController *)aViewController
         withBarButtonItem:(UIBarButtonItem *)barButtonItem
      forPopoverController:(UIPopoverController *)pc{

    //Grab a reference to the popover
    self.popover = pc;

    [barButtonItem setImage:[UIImage imageNamed:@"menuButton.png"]];

    UINavigationItem *navItem = self.navigationItem;
    [navItem setLeftBarButtonItem:barButtonItem animated:YES];
}

-(void)splitViewController:(UISplitViewController *)svc
    willShowViewController:(UIViewController *)aViewController
 invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem{

    //Remove the barButtonItem.
    [_navBarItem setLeftBarButtonItem:nil animated:YES];

    //Nil out the pointer to the popover.
    _popover = nil;
}
#pragma mark -

Solution

  • I just modified your method, why don't you try this instead

    -(void)showSplitViewControllerInView:(UIView *)view
                withDetailViewController:(id)rightViewController{
    
        UIStoryboard *mainStoryboard        = [UIStoryboard storyboardWithName:@"iPad" bundle: nil];
    
        UINavigationController  *leftNavController;
        UINavigationController  *rightNavController;
    
        MenuPrincipalVC  *leftViewController     = [mainStoryboard instantiateViewControllerWithIdentifier:@"MenuPrincipalVC"];
        leftViewController.title            = @" ";
    
    
        leftNavController                   = [[UINavigationController alloc] initWithRootViewController:leftViewController];
        rightNavController                  = [[UINavigationController alloc] initWithRootViewController:rightViewController];
    
        leftNavController.toolbarHidden                 = FALSE;
        rightNavController.toolbarHidden                = FALSE;
        leftNavController.navigationBar.translucent     = TRUE;
        rightNavController.navigationBar.translucent    = TRUE;
        leftNavController.toolbar.translucent           = FALSE;
        rightNavController.toolbar.translucent          = TRUE;
    
        UISplitViewController   *splitViewController    = [[UISplitViewController alloc] init];
        splitViewController.viewControllers             = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];
        splitViewController.delegate                    = rightViewController;
    
        if ([splitViewController respondsToSelector:@selector(setPresentsWithGesture:)]) {
            [splitViewController setPresentsWithGesture:NO];
        }
    
        view.window.rootViewController      = splitViewController;
    }