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
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];
}
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.
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
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.
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];
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/