presentViewController width in landscape mode - ios

When presenting a view controller, I would like it to take 100% of the screen width/height on iPhone portrate mode, but take part of the screen in landscape (like this):
And to be partial on iPad. The following code does everything except the partial on iPhone landscape:
SQLProEditConnetionViewController * editConnectionViewController =
[[SQLProEditConnetionViewController alloc] initWithConnectionModel: nil];
editConnectionViewController.delegate = self;
UINavigationController * navController =
[[UINavigationController alloc] initWithRootViewController: editConnectionViewController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
navController.preferredContentSize = CGSizeMake(320, 620); // size of popup view
[self presentViewController: navController
animated: YES
completion: nil];
Any ideas how I can properly get this to work for iPhone landscape mode?

Change this: modalPresentationStyle in your code.
navController.modalPresentationStyle = UIModalPresentationFullScreen;
Hope this will work...!!

On iPhone and iPod touch, the presented view is always full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.

It turns out that I was seeing this due to the iPhone SE simulator. On larger devices it works how I want it.

Related

Presenting the ViewController in full screen

I am presenting a view controller in a button action as follows,
PromptController *obj = [[[PromptController alloc]initWithNibName:#"PromptController" bundle:nil]autorelease];
UINavigationController *navigation = [[[UINavigationController alloc]initWithRootViewController:obj]autorelease];
[self presentViewController:navigation animated:YES completion:nil];
[AVSession stopRunning];
But it is not presenting on the full screen of the phone. It is presenting as follows
How to present it on the full screen. Any help is really appreciated
In iOS 13 the default presentation style has changed. If you want iOS 12 presentation style, you can change the modalPresentationStyle to .fullScreen.
Swift Version
navigation.modalPresentationStyle = .fullScreen
Objective C
navigation.modalPresentationStyle = UIModalPresentationOverFullScreen;

UITraitCollection remains same for iPhone / iPad

In iOS 8.3, I present a view controller with the following code:
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:nav animated:YES completion:nil];
Upon presentation in my iPad simulator, I check the UITraitCollection property of my view (po self.traitCollection) in the viewDidLoad() method and here is what I get:
<_UITraitNameHorizontalSizeClass = Regular,
_UITraitNameVerticalSizeClass = Regular>
I switch the simulator from iPad to iPhone (5s or 6) and I still get the Regular horizontal size class trait in my view. iPhones should have an Compact horizontal size class trait.
Since the horizontal size class is wrong, the wrong size class design is loaded from the storyboard. Any ideas why the framework is providing a wrong size class?

Wrong Size-Class of UIViewController shown with UIPopoverController

I am working on universal iPhone/iPad application with universal storyboard. For some ViewControllers I'm using size classes if they has some specific layout on iPad.
I have one ViewController that needs to be presented modally on iPhone but on iPad it needs to be shown in UIPopoverController.
UINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:#"ComposeMessageNavigationController"];
ComposeMessageViewController *viewController = (ComposeMessageViewController *)navigationController.topViewController;
//Prepeare my view controlller
...
if (IS_IPAD) {
UIPopoverController * popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CGRect popoverFrame = CGRectMake(screenSize.width / 2, screenSize.height / 2, 1, 1);
[popover presentPopoverFromRect:popoverFrame inView:self.view permittedArrowDirections:0 animated:YES];
} else {
[self presentViewController:navigationController animated:YES completion:^{
}];
}
It works pretty good but there is problem with Size Classes. I made some changes on storyboard at wRegular/hRegular Size Class but on iPad in UIPopoverController still showing iPhone layout. It's because of size of popover is lower then iPad screen. Can I make my changes in Interface Builder with Size Classes to show them in popover on iPad but ignore on iPhone?
Using setOverrideTraitCollection on the popover view controller should allow you to use the regular x regular for an iPad.

UIPopoverController displayed as modalViewController in iOS 8

I just ran into a very frustrating problem. I don't know if it's an iOS8 bug or it's something else.
I'm loading the view from a nib, which looks like this:
Here ist my code:
UIViewController *popoverViewController = [[UIViewController alloc] init];
[popoverViewController setView:poppverViewFromNib];
_popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverViewController];
[_popverController presentPopoverFromRect:CGRectMake(100, 100, 10, 10) inView:[self view] permittedArrowDirections:UIPopverArrowDirectionAny animated:YES];
The iOS simulator as well as the real device are displaying the viewController modally like you can see here:
EDIT
As requested in comments, I tell you what I expect when using UIPopoverController:
I expect an UIPopover, not a modalViewController.
So here my question to all of those how didn't get it: Why does my UIPopoverController does not display as a popover but as modalViewController? How can I fix it?
Read the documentation. Popover presentation is only available for horizontally regular size classes. Currently, this is only on iPad. Popover presentation on iPhone will always be executed as full screen modal presentation. See here.
You are lucky that iOS8 doesn't crash, as iOS7 and below, if you used UIPopoverController on a phone idiom, your app would crash. UIPopoverController is deprecated in iOS8 in favor of popover modal presentation. This is why your app does not crash.
You could keep the same code for UIPopoverController as iOS 7
just set ViewController.preferredContentSize = CGSizeMake(300, 290);
It will work.
Other Solution
iOS 8 has a new PopOverController called UIPopoverPresentationController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *navController = [storyboard instantiateViewControllerWithIdentifier:#"Terms_NC"];
navController.preferredContentSize = CGSizeMake(300, 290);
// Present the view controller using the popover style.
navController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:navController animated: YES completion: nil];
// Get the popover presentation controller and configure it.
UIPopoverPresentationController *presentationController =
[navController popoverPresentationController];
presentationController.permittedArrowDirections =0;
presentationController.sourceView = self.view;
presentationController.sourceRect = CGRectMake(100, 100, 300, 340);

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