I have a root view which contains a scroll view which contains a (content) view. The content view contains many child controls. Using the simulator, when I change orientation, none of the views, including the scroll view changes orientation. For example the image below starts out in portrait mode and all controls are played out correctly, but moving to landscape mode just shows portrait mode horizontally:
All of this was laid out using Interface Builder, so I don't have much code in the control view file besides some IB outlets to the controls.
Is there some sort of constraint that is preventing the reorientation of all the controls and views? Or do I always have to lay these out manually on orientation change?
First you need to check you have allowed the app to rotate by checking the orientations you want are ticked:
Click on the top-left corner (Show the Project Navigator)
Select the name of your project
See what is under General->Deployment Info->Device Orientation.
Adjust the tickboxes accordingly.
Update:
Also slide up on the simulator and check that rotation isn't locked for the device.
Try putting this in your AppDelegate/view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
(I don't think it's a constraint/layout issue as the status bar isn't even rotating)
Related
I am developing an app in IOS6. I am using storyboard and in my summary I have only portrait mode checked for Supported Interface Orientations. This allows my entire app to be locked into portrait mode without any extra programming.
In one of my viewControllers I have a subview (UIView) that is hidden and won't appear till a button is clicked. Once the button is clicked and the subview appears, it takes over the screen and displays images in a slideshow. I would like to make this subview have the ability to autoRotate because some of the images are in landscape. Is there a way to programatically allow this subview to be able to do this, even though the rest of the app is locked in portrait mode?
If you want to enable landscape in a single view controller and disable it elsewhere everything gets a bit complicated.
Essentially you need to set up all your view controllers to only allow portrait via supportedInterfaceOrientations. Then on your single view controller that you want to allow landscape on you can enable it via supportedInterfaceOrientations.
Lastly you then check all the supported orientations for your target.
Its a bit ugly but it works.
I'm making an application for iPad in Xcode in template Master-detail application. I need to do a design for portrait mode and another for landscape mode. My first idea was make two UIViews and make a rule: if portrait, show View1, if landscape, show View2. But I have text fields in it and when the user will be typing something inside and then rotate the device, text will be deleted, because it will be another UIView... Can anybody help me, how to do it, please?
You can have one view and use springs and struts or use autolayout.
You can also add views and hide/show them based on the orientation change.
You can change the size and position of the view on orientation change.
I have created a binary clock and am using the
willAnimateToInterfaceOrientation: duration:
method to place the on/off buttons for either the portrait or landscape orientation. I have two tabs, the first of which is the binary clock itself, and the second of which are instructions for how to read the clock.
Here's the issue. The iPad's main screen automatically switched from portrait to landscape, so I can start my app in either orientation. The iPhone, on the other hand, only displays its main screen in portrait orientation. This is fine, but when I fire up my app, push either tab button, then change the orientation, while the screen (clock or instructions) changes orientation, selecting the other tab button displays that content in the previous orientation. Within the same view (clock or instructions), orientation changes perform perfectly, but when switching from one view to the other, after having changed the orientation, the content is not displayed correctly.
In other words, say I fire up my app on the iPad in landscape orientation. By default, the binary clock view appears. Were I to change to portrait orientation, the clock changes as expected. Were I then, keeping my iPad oriented in portrait mode, to press the instructions tab button, either the content and the iAd banner (or sometimes just the iAd banner) is displayed in landscape orientation. The only solution, thus far, is to change the orientation from the current setting to the other, then back again, but that is hardly acceptable.
Is there a different method I can use to check the orientation when the view is called and display the content correctly? Obviously what I have is not working correctly.
If you move things dinamically on the view basing on the orientation, you have to check the current orientation in two places:
in the willAnimate... Method, and this is ok. This method is called when a rotation occurs AND the main VC view is visible.
in the viewWillAppear method!
If the orientation is changed when a VC is not visible, the willAnimate... Method is not called. So, before displaying the view, you should check the device orientation and setup your view/sub views correctly.
Simply use [[UIDevice currentDevice] orientation]; method in viewWillAppear to check what is the current orientation and setup your view correctly
NEW EDIT:
I have narrowed my problem to this - i have a view that i add to my main view. That view is nib file in portrait orientation. That view can be added both in landscape or portrait mode. After adding it as subview how do i tell it, device is now in landscape mode, you should autoresize to fit?
OLD:
/*
I have a view, that is loaded via [NSBundle mainBundle] loadNibNamed. When button show is pressed view should show, and likewise when button hide is pressed view should hide. And this works ok.
Problem is with when device orientation is changed (lets say from portrait to landscape mode). If view is shown it resizes ok, and everything works fine. But if view is hidden, and i rotate the device and press show, view is shown, but not adjusted to new layout. It retains its original dimensions.
It is as automatic resizing is only applied to visible components. Is there some way to force resizing of the view?
*/
When you add your view, use the following:
[subViewFromNib setBounds:[viewYouAddedSubviewTo bounds]];
I made an iPad application in which I want to support orientation, so I've written this code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//return YES;
return (interfaceOrientation==UIInterfaceOrientationPortrait||interfaceOrientation==UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
I've created a few tables in portrait mode, so when I rotate my app, the tables still comes according to portrait mode only, but the table inside my view doesn't autoresize.
You need to make sure the table view itself is set to expand and contract in both directions when autoresized - this is easiest set in IB by clicking on the table view, then clicking on the ruler sidebar header tab, then making sure that all of the autoresizing options are turned on - resizes both directions, sticks to all corners.