I have one view, which is fullscreen. I want to add to this view another view of my VC. When I add this VC view as subview to to fullscreen view I need to rotate this view to landscape. My VC has methods for forced rotation, but the view isn't displayed in preferred interface orientation, it is displayed in portrait. I would like to know, if there is a way how to achieve force rotation when adding a view as subview?
Thanks
As far as I know there isn't.
You can apply a transform to a view to rotate it.
self.view.transform = CGAffineTransformMakeRotation(M_PI * 0.5);
Related
I have a UIViewController, which launches a modal view controller. Both have orientation support. If i rotate with the modal view controller there, it doesn't tell the view controller behind it that rotation has happened, and so when the modal view controller is dismissed, the original view is in the right orientation, but at the original sizes (e.g. i rotate it to be 480x320, the text and other items will be the correct way up for the new orientation, but will still be arranged in their 320x480 layout). How do i let the view controller know rotation has occurred?
use NSNotification.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// send a notification here
}
In your ViewController behind, add an observer and call a method to fix the layout.
An old SO answer explaining the sytntax for NSNotification
I hope its useful
I have an OpenGL app which supports dynamic device orientation. I can rotate the device to any of the 4 physical orientations and everything works as expected.
Now I've added a modal view controller so that you can get a settings view (this is non-OpenGL). The modal view controller also supports any device orientation.
However, if I present the modal view controller in orientation A (e.g. portrait) and dismiss it in orientation B (e.g. landscape-right), after it is dimissed, the OpenGL view is corrupted (the aspect ratio looks wrong). I have to orient the device to a different orientation for the OpenGL view to 'correct' itself.
When the modal view controller is dismissed, it's like the app thinks that it's already in orientation B, so it doesn't ever rotate the OpenGL view.
If I disable rotation on the modal view controller, then if I present the modal controller in orientation A, rotate the device to orientation B (the modal view controller no longer rotates) and dismiss the controller, the OpenGL view gets willRotateToInterfaceOrientation/didRotateFromInterfaceOrientation and correctly orients to orientation B.
Is there any way to preserve the dynamic orientation of the modal controller, yet have the OpenGL view also properly rotate after the modal controller is dismissed?
Thank you.
I had a similar issue with a custom action sheet, and decided that the simplest answer would be to temporarily disallow rotation while the view is presented. You can see an example of this in the Apple Notes app, whenever an action sheet is presented the orientation becomes locked.
I know you've already tried this and it works, I just think you should consider that as a valid solution.
I'm not sure how to solve it otherwise, you would probably need to store any changes in orientation in your modal view controller and pass them back to the OpenGL view controller, either at the same time or once at the point of dismissing the settings view, then manually re-render.
I have a UITabBar with 2 bar items. The initial orientation of the device is portrait. If I rotate the device to landscape while being at tabBarItem2 the whole thing(Status Bar, TabBar, ViewContent2) rotates fine, but when I press the tabBarItem1 the ViewContent1 is still in Portrait. It also happens if I'm in tabBarItem1, then rotate device to landscape and I go to tabBarItem2.
I'm using the willRotateToInterfaceOrientation method on each view controller to move things.
I think this is happening because it is triggering the actual viewController's willRotateToInterfaceOrientation method and not on both of them.
Any ideas on how to fix that?
Both view controllers need to have
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
I have an application which is focused around a bunch of viewControllers in portraitmode, but on a specific detail view i need to open another view if the device is rotated to landscape mode.
So the user will look at the information view in portraitmode and if the user then rotates the device to landscapemode then a new view is displayed with additional information. If the user rotates back to portrait then the added view needs to be removed so the "original" detailview is visible.
It's important that the "original" detailview is not rotated to landscape - Only open a new view in landscape mode.
I've tried using shouldAutorotateToInterfaceOrientation: and managed to have it open a viewController, but it's not being shown in landscape view so it looks all messed up plus I'm having some trouble getting the view to disappear when i rotate back to portraitmode.
How do i do this?
Check if the orientation has changed using the View controllers did change orientation methods and if its rotated to landscape add ur landscape view and when the device is rotated to portrait remove the view from the view controller's view.
in shouldAutorotateToInterfaceOrientation
if(UIInterfaceOrientation == UIInterfaceOrientationPortrait){
NewView *newViewController = [[NewView alloc]initWithNib:#"NewView" bundle:nil];
[self.navigationController pushViewController:newViewController animated:NO];
}
you can repeat this for all the other orientations as well.
Using shouldAutoRotate didn't work since the view that gets opened will be opened in portraitmode and not landscape.
I ended up with a solution using beginGeneratingDeviceOrientationNotifications and shouldAutoRotate in the subview.
Is there any way when I rotate an iPad split view app that my view could take up the full screen instead of the menu or resize it? I like the portrait mode with the menu in the button.
How would I go about doing this?
If you're asking if you can hide the master view when a UIScrollView is rotated to landscape orientation, you can't. That's not what UIScrollView is for. You'll have to write your own view controller class.