I would like to have my buttons arranged a specific way for my portrait view and and different way for my landscape view. I would also like to be able to add things to my landscape view that might now have been in my portrait view. The reasons i know this is possible is obviously, the calculator app that comes with every iphone. When you tilt it sideways into landscape it gives you a whole new set of buttons. Does anyone know how to create a custom portrait view that is loaded when the iphone is right side up and how to create a custom landscape view when the iphone is on its side with different buttons?
You can try having two separate nib files for each orientation. You can customize the nib based on that.
Create two different view controllers (i.e. NIB files or items in your storyboard). Call the classes MyViewControllerLandscape and MyViewControllerPortrait.
Create a third view controller class programatically. Call it MyViewController, and make it the parent class of the landscape and portrait controllers.
This makes it so that you can put all the common code for the two controllers in the parent class and put only the orientation specific code in the other two.
Follow the instructions at http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html#//apple_ref/doc/uid/TP40007457-CH101-SW26 to see how to switch between the landscape and portrait viewControllers.
Related
If you scroll down a bit at this Apple Developer Page you'll find the section "Creating an Alternate Landscape Interface". The basic approach described there is to present a different NIB file as a modal view when orientation changes. I am using the Storyboard feature, so I don't have NIBs. How do I load a different "scene" in that case?
Besides that, I am using a Tab Bar controller, I don't want to show a modal view. I just want to replace the current portrait view with a landscape view designed with interface builder and keep my tab bar. What would be the Storyboard way to achieve the task "Creating an Alternate Landscape Interface"? Thank you.
When you add a view controller to the storyboard it comes with a view. Call that the container view. Add two views to the container view: a portrait view and a landscape view. Set the dimension of the portrait view and the landscape view appropriately using the size inspector. Add buttons, more views, labels or whatever to the portrait and landscape views as needed for your application. Then when the orientation changes hide one view and show the other.
You can setup a navigation controller and one main view. Then you can use a template view for the portrait and landscape layouts (2 additional views).
You will need to setup the controls on the main view and make sure each one has a unique tag. Your main view will not be used, instead you will copy the controls to the two template views and set them up based on how you want each view to look. The benefit to this is each view will retain its tag which becomes a very important piece of this implementation.
Doing this you use a hybrid approach in regards to writing some UI code and using Interface Builder. After getting the two templates setup, create a unique identifier for each one. You will have to write some logic to handle the view and its subviews. A recursive method to return a collection of these based on the template you choose.
The core logic in the root view controller implementation will need to check for isPortrait and based on this you will want to load the correct view based on the identifier.
Experiment with this concept and see if it works for you. The main benefits to not using two separate views with unique controls (not the shared approach with same tags) is that you maintain access to your original subviews. Any instance variables you define in your view controller that points to a text filed, label, etc... continue to do so regardless of which template view is used. This maintains the model, view, controller approach as the data structure remains unchanged.
Using this approach you can still maximize the use of interface builder, and layout the templates for each view, while still having the flexibility to to write some custom UI code if you desire. Using only interface builder can be a bit limiting at times, and writing custom code based on orientation locks you in to a bit of tedious work.
Hope this helps some.
You can make a xib file that contains 2 uiviews, one fore portrait and one for landscape.
Assign as file's owner of the xib, the same viewcontroller of the view thet you have in the storyboard.
In viewDidLoad load the xib file, and add the appropriete view for portrait or landscape.
So if you have a storyboard with many viewcontrollers, you can set the two possibility (portrait or landscape view) only in the viewcontrollers that you are interested to change the orientation.
I used this solution and work very fine !
I want to load in an UISplitView an iPhone XIB, but it should be resized to full screen of the iPad... How can i do it? I dont want to convert the XIB itself!
I have read all the other solutions, but I do not want a second XIB, I just want to show it on both devices iPhone and iPad in its specific size.
So if I load it on the iPad by using the UISplitView, it should be in the full size, and if I load it on the iPhone, it should only have the iPhone size.
First off, there's no such thing as a UISplitView.
From the documentation:
The UISplitViewController class is a container view controller that manages the presentation of two side-by-side view controllers. You use this class to implement a master-detail interface, in which the left-side view controller presents a list of items and the right-side presents details of the selected item. Split view controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.
So UISplitViewController is just a container. You just pass a master view controller and a detail view controller to it. The master view will be displayed in a popover controller in portrait orientation.
I think either I misunderstood you or your approach is wrong. The reason why this class is not supported on the iPhone is because it wouldn't make any sense. You can't just "resize the splitview" or whatever, you have to redesign your interface separately for the phone. It's difficult to give you any concrete suggestion without knowing what you're doing. Figure out what are you trying to achieve, have a design, make separate nibs for each device and try to reuse code and views as much as possible.
Matt Gemmell wrote a SplitViewController that you can use as subview for the iPad (http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad/). You can check the source if you could use this for iPhone too. I found the source too heavy, I simply created an UITableView that loads other views when selecting a row (sort of a fake splitview).
I have a multitab application where I want the display orientation the same for one tab and dynamic for the other, that means I need for example for
Tab1 = always portrait orientation
Tab2 = automatic detection plus orientation
I have tried to disable the orientation on Tab1 but that will disable the orientation in the whole app.
Any help?!
From Apple docs:
"Tab bar controllers support a portrait orientation by default and do not rotate to a landscape orientation unless all of the root view controllers support such an orientation. When a device orientation change occurs, the tab bar controller queries its array of view controllers. If any one of them does not support the orientation, the tab bar controller does not change its orientation."
So the answer is no you cannot do what you are trying to do, it's an all or nothing kind of situation.
If you have not already used, I think calling different UIView for different Tab will help you to do so.
If you have used it, then making 2 different ViewControllers and handling the same thing different may help you to do so.
I created a app with the iOS 4.1 SDK.
In this app I did the following: I add two UIView's as subview to the Window of the Application. One view is a navigationcontrollerview and the other is a view that displays advertisement. The user can then navigate trough the app will the ads are displayed uninterrupted.
Now comes the problem: I wanted to add the option to rotate the device from portrait to landscape and back. The problem is only the first view (in my case the navigationcontrollerview) is rotated without problem. The second view is never rotated. Documentation from Apple confirms that this is the default behavior.
So, how do I get my second view rotated? Do I need to restructure my application? And why is the second view never rotated? That doesn't make any sense to me.
Are you just adding the second view (the one that doesn't rotate) as a plain UIView? If so, try adding it after containing it within a UIViewController class. I had the same issue in my app not so long ago. instead of [window addSubview:sampleView], I did [window addSubview:[sampleViewController view]]; where sampleViewController subclasses UIViewController.
In general, always use corresponding view controllers and contain views in them and then add subviews to avoid these issues.
I've been digging at this for a few days and can't seem to figure it out.
My app launches in landscape and supports only landscape orientations. Works fine.
My app delegate instantiates a root view controller, view is built from an XIB and populated with an image in viewDidLoad. The underlying image is landscape size (1024x768). Looks fine on the screen.
Once the app is launched, I wait for user interaction, and then present a new view controller along with a new view from a new XIB. This second vc/XIB is also landscape (as specified in interface builder). For practical purposes my first and second XIBs are near identical - both landscape views containing one imageview outlet occupying the entire screen.
I'm using off-the-shelf UIAnimationTransistion when I move between my root view (basically a splash screen/menu) and my first real content view. My problem is that, no matter what I do, the first animation transition is generated as if the view is in portrait mode. If I specify a left flip, it flips top to bottom. If I specify a right flip, it flips bottom to top. If I specify a curl up, it curls horizontally.
Once I've transistioned into my second view controller (where most of my apps content is), all the animations work exactly as they should.
How can I get the first view that is loaded (from my rvc) to orient itself properly so that my animations are consistent moving between this first rvc and the second content vc?
Like jmont said, it could be a -shouldAutoRotateToInterfaceOrientation problem. It could also be that you need to specify 'InitialInterfaceOrientation' in the info.plist with a value of 'Landscape (left home button)' or 'Landscape (right home button)'. The last possibility would be to directly set the interface orientation.