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;
}
Related
In my app I've a UITabBarController that contains 3 UINavigationController. I can freeze orientation for any UIViewController. For this I've implemented UITabBarController and UINavigationController. But problem occurs when I push a UIViewController from another one that was in Landscape. The newly pushed UIViewController should be in portrait but it remains in Landscape. I know problem may be unclear so I am attaching scrrenshots.
Lets consider its VC-A.
Pressing edit from VC-A goes to this VC-B. VC-B is:
This VC-B should always in portrait. VC-A can be in Landscape or portrait. When VC-A is in landscape and I press edit the VC-B is pushed and VC-B comes in landscape mode though I implemented these methods in VC-B:
-(BOOL)shouldAutorotate {
return UIInterfaceOrientationMaskPortrait;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
Your shouldAutorotate needs to return a BOOL not the mask, so code should be
-(BOOL)shouldAutorotate {
return YES;
}
All child view controllers in a tab bar controller or navigation controller must have the same set of supported orientations. This is discussed near the bottom of the following document.
https://developer.apple.com/library/ios/qa/qa1688/_index.html
I am trying to add a modal view to my ipad app. All views are supposed to be in landscape mode.
For style I chose form or a page sheet.
Here is the problem. When I add modal view to my view with the following code:
TempController *tmpViewController = [[TempController alloc] initWithNibName:#"TempView" bundle:nil];
tmpViewController.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:tmpViewController animated:YES];
My modal view is displayed in landscape mode, but the view below it is displayed in Portrait. After modal gets dismissed, view is still in potrait. If I don't attach modal to the view, the view is displayed fine, in landscape mode.
I played with statusBarOrientation and shouldAutootateToInterfaceOrientation, but still no luck. I am running xcode 4.4.1 on Mountain Lion
update: this is my shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
return NO;
}
A quick note: presentModalViewController:animated: is deprecated. Apple recommend using presentViewController:animated:completion:.
To make sure I understand the question, the view controller that presents the modal view controller displays correctly in landscape mode, but then as soon as it presents the modal it changes itself to portrait mode, even though the modal view controller also displays correctly in landscape? Is this happening with an iPhone/iPod touch or iPad? What does your code look like for the shouldAutoRotateToInterfaceOrientation method of the presenting view controller?
Ok I have an interesting issue on an iPad application I am developing.
When the app launches in portrait mode the layout works as expected. I rotate the iPad and the rotation works fine.
When the application launches in landscape mode there is additional white space appearing and the layout does not work as expected. But when I rotate the application to portrait it rotates just fine. It also lays out fine when I rotate it back to landscape.
What could be causing this problem? The view controller in question is a view controller that contains a UINavigationController (I had to add in a header). I wonder if it is something with UINavigationController.
Your view is expecting Portrait mode upon launch. In your view Controller, you need to let it know to look for orientation, and load the corresponding view.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight))){
self.view = landscape;
}else if(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
self.view = portrait;
}
return YES;
}
Ok so what was strange in my application is that the layout would become correct when the tab controller switched tabs back to the view that was being funky. So, I added a hack in order to switch between the tabs before the makeKeyAndVisible of the main window.
I did try your suggestion WrightsCS. The real reason it didn't work is because I'm loading UINavigationController's view in the sub view of the page, so I didn't really have control of the layout that was messing up. The top bar of the navigation controller was loading a little lower than it should have been.
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;
}];
i have got 2 GUIs and 2 Controllers
1 is called landscapeguicontroller and the second is called highguicontroller.
Now generally i call the highguicontroller, and when i rotate my iphone it detects that and then it shows the landscapeguicontroller:
Code:
landscapeguicontroller *neu =[[landscapeguicontroller alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:neu animated:YES];
[self dismissModalViewControllerAnimated:YES];
The Problem is that then the animation pushes the new window from the beyond side of the iphone up into the window.
In the Landscapeguicontroller,i have added to the the following lines:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
when i want go back to the highguicontroller i call:
[self dismissModalViewControllerAnimated:YES];
that all works , but just in the second animation i see the correct "rotation animation".
Have you got any suggestions?
So a short Problem description:
in the 1. animation from high to landscape, the landscape is pushed into the window
BUT in the 2. animation from landscape to high, the rotation looks like a real rotation...
i want the 1.animation look like the 2. animation
best regards
Ploetzeneder
To avoid "The Problem is that then the animation pushes the new window from the beyond side of the iphone up into the window.", try setting the view controller's modalTransitionStyle property to one of the following, whatever you prefer:
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
} UIModalTransitionStyle;
Also, if you want to avoid the animated rotation, you can set your shouldRotate... method to disallow other orientations, but then set up to receive notifications when the device physically changes orientations, and present your modal viewcontroller when in the appropriate orientation for it. See Apple's "AlternateViews" sample code for an example of this.
The notifications reflect the physical orientation of the device, and you can receive them whether the interface is allowed to change or not. (You can look at the UIApplications's statusBarOrientation property to see what orientation the UI is in).
It sounds like you want the sequence to go like this:
Physically rotate the device from portrait to landscape
Animate the portrait view (highguicontroller) to landscape
Push the landscape view (landscapeguicontroller) up from the new "bottom" of the screen
If that's right, you'll need to have something like the following in your highguicontroller implementation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}
This will take care of step 2 (it will rotate the portrait view to landscape in either direction).
Then you'll want something like this:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation == UIInterfaceOrientationPortrait) {
[self presentModalViewController:landscapeguicontroller animated:YES];
}
else {
[self dismissModalViewControllerAnimated:YES];
}
}
That should present the landscape view after the rotation animation is complete and then dismiss it after the device is rotated back to portrait.
Hope that helps!