How to hide master view in UiSplitviewcontroller in ipad

后端 未结 9 1594
野的像风
野的像风 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 11:07

    This works:

    Attach the "hide" method to your button, for example:

    UIBarButtonItem *hideButton = [[UIBarButtonItem alloc] initWithTitle:@"hide"
                                             style: UIBarButtonItemStylePlain
                                            target: self
                                            action: @selector(hide:)
                                  ];
    
    [self.mainView.navigationItem setLeftBarButtonItem:hideButton];
    

    In this code, the "self.mainView" is the view controller in the navigation controller in the second view of the splitview - just as a reference.

    The hide method looks like so.

    -(void)hide:(id)sender
    {
        UIViewController *masterController = [self.viewControllers objectAtIndex:0];
    
        CGRect selfFrame = self.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.view setFrame:selfFrame];
    
        [UIView commitAnimations];
    
    }
    

    This is the starting point, obviously more logic needs to be done to take care of rotation, showing it again, etc...

    I hope this helps.

    Tested with iOS5 and Xcode 4.3

提交回复
热议问题