navigation stack within child view controller - ios

I am putting a UINavigationController inside a container view like so (this in a full screen UIViewController subclass):
UIViewController *litteViewController = [[UIViewController alloc]initWithNibName:nil bundle:nil];
UINavigationController *littleNavigator = [[UINavigationController alloc]initWithRootViewController:litteViewController];
UIView *containerView = [[UIView alloc]initWithFrame:CGRectMake(100.0, 100.0, 250.0, 320.0)];
littleNavigator.view.frame = containerView.bounds;
[self addChildViewController:littleNavigator];
[containerView addSubview:littleNavigator.view];
[self.view addSubview:containerView];
[littleNavigator didMoveToParentViewController:self];
Now this works as expected and littleViewController appears in the rect I expect with a nav bar at top. Now let us say as a result of some interaction inside littleViewController something like this happens
-(void)someButtonAction:(id)sender{
UIViewController *secondLittleViewController = [[UIViewController alloc]initWithNibName:nil bundle:nil];
[self.navigationController presentModalViewController:secondLittleViewController animated:YES];
}
unfortunately this subsequent controller winds up being presented full screen. Now I've done exactly this before inside popoverControllers and splitViewControllers and they've behaved exactly as I want this to, a navigation stack is built within the little rectangle it was started in.
How can I build a navigation stack inside a container over in an arbitrary CGRect?

On iPhone and iPod touch, the presented view is always full screen. So you need change to pushViewController
Glad I can help

Related

ios7 - showing a view controller on top of another but not in full screen

When i press a button on my view controller, i would like to present another controller on top of it, but in the middle and not in full screen.
How could i present a controller on top of another controller in such way?
If you are trying it on iPad you can always set up a Popover that contains your new view.
UIYourNewViewController *vc = [[UIYourNewViewController alloc] init];
UIPopoverController *popVc = [[UIPopoverController alloc] initWithContentViewController:vc];
[popVc setPopoverContentSize:*the size that you want or your resized vc*];
[popVc presentPopoverFromRect:*position of the screen you want to show the popover* inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
With this you will create a Popover of the size of the view of your viewcontroller and you can pop it up in the position that you want.
To make sure it works on iPhone also, you should create a category for the UIPopoverController and add this method in the .m
+ (BOOL)_popoversDisabled {
return NO;
}
Remember to declare the method in the .h of the category.
You need to set this property to your controller before presenting it.
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:controller animated:YES completion:nil];
Yes it is possible you have to present view controllers view with animation. Please refer the below code. You will get some idea its showing animation from bottom of screen to middle of screen.
YourViewController *viewController = [[YourViewController alloc] init];
[viewController.view setFrame:CGRectMake(0, -(CGRectGetHeight(viewController.view.frame)), CGRectGetWidth(viewController.view.frame), CGRectGetHeight(self.view.frame))];
[self.view addSubview:viewController.view];
[UIView animateWithDuration:0.8 animations:^{
[viewController.view setFrame:CGRectMake(0, 0, CGRectGetWidth(viewController.view.frame), CGRectGetHeight(viewController.view.frame))];
} completion:^(BOOL finished) {
[self.navigationController pushViewController:viewController animated:NO];
}];
In iPhone, presenting a UIViewController is always fullscreen. On iPad, you can use a UISplitViewController or build a custom container, but the view controllers you present will fill the containers in both a UISplitViewController and custom container controller.
To present content on only part of the screen, you can animate a UIView onto your view controller. There are ways to present a view controller and still have another view controller show up behind it, but this is not recommended.
Check out this other question for more information on creating a custom container view controller..

Prevent resize of UINavigationController

I try to implement a custom split view for an iPad application.
On the left side, I have a ViewController which contains the navigation.
The right side should contain a NavigationController with a navigation bar. When I initialize the NavigationController, I set the frame to the correct width:
FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
[firstView.view setFrame:CGRectMake(186, 0, 838, 748)];
[firstView.view setAutoresizesSubviews: NO];
UINavigationController navController = [[UINavigationController alloc] initWithRootViewController:firstView];
[navController.view setFrame:CGRectMake(186, 0, 838, 748)];
navController.navigationBar.topItem.title = #"Title";
But somewhere between viewWillAppear and viewDidAppear the frame.width from navController.view changes back to 1094 px. And so my title label is not correctly centered (within the visible area). Can I prevent the NavigationController from resizing? I already tried setAutoresizesSubviews: NO but this doesn't seem to work.

UIViewController transparent background

I am creating a viewcontroller in this way:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"PhotoViewControlleriPhone" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:NO];
vc.view.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y + 64, imageView.frame.size.width, 200.000000);
vc.view.layer.cornerRadius = 10; // this value vary as per your desire
vc.view.clipsToBounds = YES;
The viewcontroller is not full screen, so you can still see the previous one. I want to be able to see it, but lock it. Just like when you use ios facebook sharing, you see the background, but it becomes darker and you can't interact with it. How can I do this?
I believe the problem is that you’re displaying it using -presentModalViewController:animated:. Using that method carries with it some assumptions about the view controller you’re hosting; one of the assumptions it makes (on iPhone-type devices, at least) is that the view controller takes up the entire screen and is opaque.
To get around this, try adding the modal view controller’s view to the current view controller’s view manually. You’ll need to set the view controller hierarchy up to match the view hierarchy, so your code would look like this:
[self addChildViewController:vc];
[self.view addSubview:vc.view];
You’ll need to adjust the incoming view’s frame to position it within its new superview, but that should allow you more freedom.
My workaround is to take a screenshot with code, pass the UIImage as a parameter to the new UIViewController, and display it as a background image. In that way it appears transparent, and the you don't have to disable the underlying controls that might be reachable/accessible.
iOS8+
You can use below code snippet for iOS8+, its worked for me
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:secondViewController animated:YES completion:nil];

How do I dismiss a modal view controller in the right side of splitViewController?

I present a modal view controller in the detail view of my splitViewController with the following code:
AddressViewController *addressViewController = [[AddressViewController alloc] initWithNibName:#"AddressViewController" bundle:nil];
addressViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
addressViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:addressViewController animated:YES];
addressViewController.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[addressViewController release];
But when I dismiss the modal view controller, it flips so that it gets behind the master view controller for a short time. When the transition is over, it "jumps" to its right place.
Does somebody know how to prevent this?

Part of the uiview doesn't call touchesBegan for view on top of uisplitview

I'm writting an ipad app with a uisplitview. Once a user taps on a button, I display another view in full screen by removing the uisplitview from the stack and pushing the new view. The problem I have is that the new uiview only gets touchesBegan for 3/4 of the screen. It seems like that is the same area used up for the uidetailview in the uisplitview. I've been trying to figure this out for a few days with no luck.
the uisplitview gets synthesized and it gets added in the didFinishLaunchingWithOptions like this:
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
then, when the user touches a button, I do this:
NewViewController *newViewController = [NewViewController alloc];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:newViewController];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController presentModalViewController:navController animated:YES];
[newViewController release];
[navController release];
Check the sizes of the bounds of the view. It should be as big as the iPad screen. That is 1024x768 (or 768x1024).
Long time ago... but maybe somebody else needs the answer. I had the same problem. My fault was that I initialized the UIWindow with portrait mode (1024+768) but this is wrong. The window, however you rotate the iPad, will never rotate and must have the portrait dimensions (768x1024).

Resources