We instanitate a UINavigationController and a UIViewController from a storyboard like so:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"AddOrder" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
UIViewController *topVC = ((UINavigationController *) vc).topViewController;
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
From here, it looks like the UIViewController isn't taking up the whole UIWindow, it looks 20 pts down like on ios6. You can even see the underlying UISplitViewController's divider at the top left if you look closely.
The issue is, when the user taps an option on the UITableView on theUIViewController we call [self performSegueWithIdentifier: sender:] which pushes a new UIViewController on, but when they rotate it, it looks like so:
A little cramped, to say the least. But now, when we go back to the first UIViewController and rotate, we get this:
Issue is, the search bar is now covered. You'll notice you cannot see the underlying UISplitViewController anymore either. As you can see, it looks like now the UINavigationBar is covering up the other 20 pts and is larger in height.
I kind of "fixed" the issue by calling self.edgesForExtendedLayout = UIRectEdgeNone; but that just shoves the UIView pretty far down. I also toyed with adding [UIViewController attemptRotationToDeviceOrientation] but nothing. In Apple's HIG it states that a navigation bar should not change it's height on the iPad, yet this is happening to me when I log out the frame.
Any ideas?
Hi You can create the view controller with these properties
And add the modal on the the application window
[self.view.window.rootViewController presentViewController:vc animated:YES completion:nil];
I think your problem will be solved by this.
Just fix it by
self.automaticallyAdjustsScrollViewInsets = NO;
Put this line in viewDidLoad method and then create other controllers.
It's only working on iOS 7 and latter.
Related
For my iPad version of the app I want to open my UIViewController as a UIPopoverController from the click of a button. So, the real code for view controller opening is below. How can I easily convert such code into opening a UIViewController as a UIPopoverController?
Code:
UIStoryboard *sb = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:#"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
UIViewController *aboutView = [sb instantiateViewControllerWithIdentifier:#"AboutViewController"];
aboutView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:aboutView animated:YES completion:NULL];
Use something like:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIPopoverController *poc = [[UIPopoverController alloc] initWithContentViewController:aboutView];
[poc presentPopoverFromRect:CGRectMake(somePoint.x, somePointY, 1.0, 1.0) inView:self.view permittedArrowDirections: UIPopoverArrowDirectionAny animated:YES];
} else {
aboutView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:aboutView animated:YES completion:NULL];
}
You can also present the popover from a button and you also can control the direction in which the popover will be presented. If you use UIPopoverArrowDirectionAny, iOS will make a smart decision for the popover to be visible.
You should also keep a strong reference to your popover and only present it while it is nil to make sure the popover is only present once. That means if the popover is dismissed, set the property holding it to nil.
A common solution is to have two storyboards, one for iPhone, one for iPad. That way you can use the popover segue in the iPad storyboard and the modal segue in the iPhone storyboard. You can readily arrange your Info.plist so that the correct storyboard loads automatically at launch time. You will still need some conditional code, though, since your code will respond differently to having a presented view controller than having a popover.
I'm using a modal transition to move between view1 to view2 and i want to use pop transition (programmatically) from view2 to view3, but it doesn't work (I am using navigation controller as root):
the code is (in view2):
view3 *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"view3"];
[self.navigationController pushViewController:controller animated:YES];
how should the code be?
All looks good to me in terms of code.
You should provide information about why this is not working... Are you getting an error? IF so where?
How do you initate the push to the new controller? Try using NSLog(#"Hello"); to make sure that this is being called correctly.
Further to this, the issue could be that the storyboard is not being returned with self.storyboard. You can always try
UIStoryboard *appStoryboard = [UIStoryboard storyboardWithName:#"YOUR_STORYBOARD_NAME_HERE" bundle:nil];
Then use
view3 *controller = [appStoryboard instantiateViewControllerWithIdentifier:#"view3"];
I have UIPageViewController which contains a couple of UIViews, in each of the view its possible to turn the UIView with an horizontal flip to a NavigationController containing only a view. I implemented this functionality but it seems that the flip only works the first time.
Here is how I flip the view in the first place:
UINavigationController *navController = [self.storyboard instantiateViewControllerWithIdentifier:#"BackViewController"];
//Pass some data to the back controller
[[[navController viewControllers] objectAtIndex:0] setDataObject:self.dataObject];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentViewController:navController animated:YES completion:nil];
And here is how I turn it back:
PageRootController *pageRootController = [[self.storyboard instantiateViewControllerWithIdentifier:#"PageRootController"] initWithData:self.mydata];
pageRootController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentViewController:pageRootController animated:YES completion:nil];
Like I said, this works good for the first time (I can flip it and then flip back), and does nothing once I tap it again. I'm new to iOS programming so if you need some more info I can paste it.
The problem was that I had a new navigation controller inside each of my views, instead of pushing and popping views from the current one.
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];
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).