如何删除拆分视图控制器的手势iOS 7

时间:2014-03-27 19:03:50

标签: cocoa-touch uisplitviewcontroller gesture

我有一个splitView控制器,默认情况下用手势

打开/隐藏菜单

enter image description here enter image description here

拥有它没有任何编码是一个好主意,但正如你所看到我添加了一个与该手势一起工作的旋转木马,但拆分菜单的手势禁用了旋转木马移动性,这是我获取UISplitViewController的代码:

显示分割视图控制器的代码


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;
}

用于在细节视图控制器上显示/隐藏按钮菜单的代码

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 -

1 个答案:

答案 0 :(得分:2)

我刚修改了你的方法,为什么不试试呢

-(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;
}