UIModalPresentationFormSheet on iPad in landscape mode - cocoa-touch

I created a UIViewController view from XIB with modalPresentationStyle set to UIModalPresentationFormSheet and everything works great in portrait mode. When I switch to landscape the view gets moved upperleft (it's not centered as it should be) and most part of it is clipped.
Any ideas why this is happening and how to solve it?
Thanks

I had this problem as well. Turned out, I had the autorotate function set to Portrait for both the modal controller and the calling controller.

In iOS 7, to solve the problem of the modal view controller to appear to the left after apparition of the keyboard (problem that I have when I present an EKEventEditViewController in UIModalPresentationFormSheet, I do :
[self presentViewController:modalViewController animated:YES completion:^{
modalViewController.view.superview.center = self.view.center;
}];

Related

How comes this UIViewController is always displayed in Portrait Mode?

When my device is in landscape mode and I modally present a view controller, this is always displayed in portrait mode, which is what I want.
However, I don't understand why other views (modally presented) are always displayed in landscape mode instead (if the current orientation of the device is landscape). The code I use is the same for all my view controllers, and the xib file orientation property is always Portrait.
This is how I push the view controller which works (it is never displayed in landscape mode):
- (IBAction)showImport:(id)sender
{
CMImportExportViewControlleriPhone *importController = [[CMImportExportViewControlleriPhone alloc] initWithNibName:#"Import-Export-iPhone" bundle:nil];
[importController setLayoutViewController:self];
//[importController setDelegate:self];
[self presentModalViewController:importController animated:YES];
[importController release];
}
thanks
If this is initial view controller and you have settings in plist file to start application in portrait mode then it would display in portrait mode doesn;t matter what is your device orientation. When you put your device in landscap mode and present new view controller, it will be landscap as it follows the status bar orientation! Before presenting new view controller try reseting status bar to portrait mode and then present new view controller. It will be presented in portrait mode! I had this similar issue in iOS 6.0.

modalViewController presented from UISplitViewController comes up as the wrong orientation

I have a UISplitViewController that is set at the rootView of my application. When viewDidLoad is called in my left view controller I do a check, then present a modal view controller using the following:
SiteConfiguration *config = [[SiteConfiguration alloc] initWithStyle:UITableViewStyleGrouped];
config.firstLoad = YES;
UINavigationController *configNav = [[UINavigationController alloc] initWithRootViewController:config];
if ([Utility isIpad]) {
configNav.modalPresentationStyle = UIModalPresentationFormSheet;
configNav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[[AppDelegate instance].splitViewController presentModalViewController:configNav animated:YES];
} else {
[self presentModalViewController:configNav animated:YES];
}
If the iPad is in landscape mode while the app loads, the modalView is shown with an incorrect orientation:
I can rotate the iPad to fix this, but WHY does it load up wrong? I have shouldAutorotateToInterfaceOrientation: returning YES in my SiteConfiguration viewController. What could be causing this?
Be careful of where you choose to present your modal controller.
I've had experience with some custom modal controllers and setting the orientation of the modal controller (and its shadows!) in
- (void)viewDidLoad:(BOOL)animated
didn't always behave as expected.
Put your code (presentModalViewController:configNav animated:YES) in
- (void)viewDidAppear:(BOOL)animated
instead. (Do this as well with any code that sets a subviews frame or does any manipulation of layers, e.g. the shadow layer and shadow properties).
As far as I can tell, the rotation may not be apparent to subviews of the rotated view until after - (void)viewDidLoad:(BOOL)animated due to threading issues (one thread may start drawing your subview or modal controller's view before rotation is passed down to the subviews (and modal controllers) by the main thread). Someone with more experience with threads than myself might be able to shed more light on this.
shouldAutorotateToInterfaceOrientation: doesn't actually rotate the interface, the app does that upon receiving a UIDeviceOrientationDidChangeNotification notification.
Try adding a check for the device orientation in the -(void) viewDidAppear:(BOOL)animated method.
To force an interface rotation, use the following piece of code.
UIDeviceOrientation toInterfaceOrientation = [[UIDevice currentDevice] orientation];
[UIApplication sharedApplication].statusBarOrientation = toInterfaceOrientation;

Dismissing modal view makes main view rotate

I have a main view that I rotate to landscape using
-(void)viewDidLoad {
self.view.transform = CGAffineTransformMakeRotation(90);
self.view.bounds = CGRectMake(-0.0, 0.0, 480.0, 320.0);
It works great. The problem is that this view can call a modal view, and when I dismiss the modal view the main view returns to portrait. Any ideas why this happens and how can I fix it?
Are you overriding shouldAutorotateToInterfaceOrientation: in your main view and returning YES for any orientation? If not, your main view thinks that it can only support portrait mode, and will autorotate back to portrait whenever it comes to the front.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}

UIActionSheet not rotating in landscape mode?

I have a UIActionSheet and I set it's view like this:
[popup showInView:[[UIApplication sharedApplication] keyWindow]];
this works fine in portrait mode, but when I switch to landscape, it stays portrait. What am I doing wrong?
Thanks.
You're showing it in the window (which is not rotated), rather than in a view controller's view (which is). Pass the main view of your currently-visible view controller instead, or use showFromTabBar: or showFromToolbar: on iPhone or showFromBarButtonItem:animated: or showFromRect:inView:animated: on iPad.
You can use this instead:
[popup showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
[popup showFromToolbar:self.view];
Special for ActionSheet within ActionSheet.

iPad Orientation issues when switching between two views and from portrait to landscape vice versa

I am building a simple app with two View Controllers, I am testing the code using the iPhone Simulator, everything seem to be working fine. The problem happens when I rotate from Portrait to Landscape or from Landscape to portrait. This is the logic of the app, the app always launched in Portrait, I have a button to on the first View to Switch from View1 to View2. On View2 I have another button to switch from View2 back to View1. Let say, I am in Portrait mode, I switch from View1 to View2, then rotate the iPad (in the simulator) from Portrait to Landscape, when I switch back from View2, i.e to go back to View1. View1 screen/view is displayed in Portrait with View2 screen displayed in the background, ie part of View2 is displayed in the background, I guess because View1 was originally in Portrait mode.
The question is.. Has anyone had this issue before, if so, any code to fix this issue, secondly, how can I identify in the code which orientation the device is and which orientation the view is in.
This method is to switch to View 2:
-(IBAction) switchToView2: (id) sender {
SecondViewController *myViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.view addSubview: myViewController.view];
[UIView commitAnimations];
}
This method is to switch back to View1:
-(IBAction) switchBackToView1:(id) sender {
[self.view removeFromSuperview];
[UIView commitAnimations];
}
From your code:
[self.view addSubview: myViewController.view];
It makes me believe that your 2 views is a subview of myViewController.view. which explains why they're both showing at the same time. it would make sense to have seperate view controllers for different views.
First i think
[UIView commitAnimations];
is not necessary :
From Apple
commitAnimations
Marks the end of a begin/commit animation block and schedules the animations for execution.
second in Interface Builder have you set the property of your controller to landscape ?
Hope this Help (sorry for my bad English)
Yes, that would happen if you dont put any orientation change handling in your code. Check out this guide on how you can set your view to automatically or manually handle adjustment on orientation change.
Or if you do have handling already, then it may be because of how you are adding/removing your views. For better handling, I think you should try the UINavigationController way of managing views. i.e., instead of addSubview: and removeFromSuperview:, you should use pushViewController:animated: and popViewController:animated: instead.
And yes, as Yoos said, [UIView commitAnimations] is not needed in your code above.
Hope this helps.