How to hide master view in UiSplitviewcontroller in ipad

后端 未结 9 1568
野的像风
野的像风 2020-12-08 10:44

Is there is any way to hide the master view in a splitviewcontroller programmatically. In my application the first screen will be of a splitviewcontroller, i don\'t need any

相关标签:
9条回答
  • 2020-12-08 10:49

    The code above didnt work for me, however, when I tried

    CGRect selfFrame = self.splitViewController.view.frame; 
    

    it did. So....this works for me.. (this code should be in your detailviewcontroller)

    -(void)hideMaster {
        UIViewController *masterController = GetAppDelegate().masterController;
    
        CGRect selfFrame = self.splitViewController.view.frame; 
        CGFloat aWidth = masterController.view.frame.size.width;
    
        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.30f];
    
        if(orientation == UIDeviceOrientationLandscapeLeft)
        {
            selfFrame.size.height += aWidth;
            selfFrame.origin.y -= aWidth;
        }
        else if(orientation == UIDeviceOrientationLandscapeRight)
        {
            selfFrame.size.height += aWidth;
        }
    
        [self.splitViewController.view setFrame:selfFrame];
    
        [UIView commitAnimations];
    
        }
    

    To allow rotation this was needed:

    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration
    {
        [super willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration]; // not sure if needed
        //By the time this method is called the bounds of the view have been changed
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
    
        if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
            if (masterIsHidden) {
                [self showMaster];
            }
        } else {
            if (self.editing) {
                [self hideMaster];
            }
        }
           [UIView setAnimationDuration:duration];
        [UIView commitAnimations];
    }
    
    0 讨论(0)
  • 2020-12-08 10:50

    Try this:

    splitVC.modalPresentationStyle = UIModalPresentationFullScreen;
    [splitVC presentModalViewController:[[splitVC viewControllers] objectAtIndex:1] animated:NO];
    

    Works on 4.2 for me!

    Here is another awesome trick that works. video link is here.

    0 讨论(0)
  • 2020-12-08 10:54

    Don't know if this is what your are looking for. For example, to hide master view in landscape mode when a button is clicked you can do the following (in the selector method)

    UIViewController *master = [splitViewController.viewControllers objectAtIndex:0];
    UIViewController *detail = [splitViewController.viewControllers objectAtIndex:1];
    
    [master.view setFrame:CGRectMake(0, 0, 0, 0)];
    detail.view.frame = splitViewController.view.bounds;   // or use master and detail length
    
    0 讨论(0)
  • 2020-12-08 10:59

    in SDK 5.0 they added new method for UISplitViewControllerDelegate that would do this easily for you. Just implement it like next and you would not see the master view:

    - (BOOL)splitViewController:(UISplitViewController*)svc 
       shouldHideViewController:(UIViewController *)vc 
                  inOrientation:(UIInterfaceOrientation)orientation 
    {
        return YES;
    }
    

    The only place when you can see it is rotation - the part of master view is visible during animation. I've fixed that in simple way, just loaded empty and black view in master.

    PS: not sure whether this is actual for i0707. But hope this could be useful for other people that now have the same issues.

    0 讨论(0)
  • 2020-12-08 11:00

    Same as answer from Jack but a one liner. Past into - (void)setDetailItem:(id)newDetailItem { ... } to dismiss the master.

    [[UIApplication sharedApplication] sendAction: self.navigationItem.leftBarButtonItem.action
                                               to: self.navigationItem.leftBarButtonItem.target
                                             from: nil
                                         forEvent: nil];
    
    0 讨论(0)
  • 2020-12-08 11:03

    Matt Gemmell created an excellent custom splitViewController called "MGSplitViewController". It is very easily implemented, heavily commented, and contains a lot of excellent features not found with a normal splitViewController (hide master view on landscape view, change placement of the split in landscape view, allow user to change size of split fluidly during runtime, etc).

    Info and demo: http://mattgemmell.com/2010/08/03/mgsplitviewcontroller-updated/

    Straight to the source: https://github.com/mattgemmell/MGSplitViewController/

    0 讨论(0)
提交回复
热议问题