Iphone View Rotation not functioning properly - iphone

I have a simple 1 screen app, with 1 View.. the view contains
a button, an textbox and a button across the top
A segmented controller across the bottom
and a MapView in between.
In portrait mode all is right with the world.. So I decided to begin to allow Orientation change...
in IB all views and elements and even the root window have autoResizeSubviews set
in My AppDelegate and my viewController I have also programatically added SetAutoResizeSubviews to yes explicitely I have set the autoResizingMask in the Root Window and the View Controller to FlexibleWidht | Flexibile Height
I have added the shouldAutorotateToInterfaceOrientation in my ViewController to always return true.
Yet, it doesn't work.. Or should I say it doesn't rotate properly.. in both portrait modes everything looks great, but both landscape modes, things don't get laid out or resized properly.. Basically all I see is the mapview, and its size gets slightly wider, but not much than the portrait mode, and it doesn't fill up the screen top to bottom.. all other interface elements with the exception of one button are invisible and it appears on TOP of the mapview.. as thought it just happened to be layed out over the view by coincidence than any design.
Anyone have any ideas what I am missing, or why?
Thanks in advance

You say "I have set the autoResizingMask in the Root Window and the View Controller" but that is a red herring. It is the buttons, the text box, the segmented controller, and the map view that have to have the correct autoresizingMask. If this view is being designed in the nib, you can set the values there and then turn the orientation right there in the nib and see what happens.
If you are unable to work out good autoresizingMask values for all those interface elements, implement didRotateFromInterfaceOrientation and perform the layout alterations in code when called upon to do so.

Related

UISegmentedControl inside UIToolbar does have wrong height for Lanfscape

Somehow the Segmented Control does not get the proper height when the iPhone is in Landscape.
It is already bad enough when rotating the simulator that the toolbar at the bottom doesn't get thinner height, but when navigating back to the previous screen and then in again, the toolbar does get the propper height, but the segmented control extends above it, and even looks much bigger.
Is the is bug in the simulator or am i doing something wrong?
After digging around another day, I found where it all went wrong!
When dealing with UINavigationControllers, DO NOT drag in a UIToolbar at all! UINavigationController comes with two bars, a top-bar for the Navigation Controller and a bottom-bar for the ToolBar - that latter one is hidden by default.
In any newly added ViewControllers, there will be a toolbar that can be populated from the IB. However, if it is not a UIBarButton, there are some issues. To use a stepper, on/off-switch or a segmented control, drag it first to the Navigation bar, and then in the left column navigator of IB, drag it to the toolbar.
This solved all the problems mentioned before

Display a control in both orientations

I've got a button designed on Portrait Orientattion, when I switch to Landscape it doesn't appear, what should I do so that it stays all the time?
Make sure you set the proper AutoresizingMasks for your UIViews. For example, it might be that your button has a y-coordinate that is larger than the device's width and has a fixed top resizing mask, so if you turn the device to landscape mode it gets clipped. Doing this...
button.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
...will cause the button to shrink its top margin, moving on screen.
In your comment you mentioned that this is a split-view app, if your button is in the root view controller of the split view, you should probably add support for restoring the root view controller as a popover.

Why is there a 20-pixel-high dark overlay over my app's navigation bar?

Once again, I'm almost entirely sure this is something dumb that I'm doing, but I've been banging my head against this one for hours & am getting nowhere.
I'm trying to restructure the view hierarchy of my app. I need to be able to detect user interface orientation changes globally in order to correctly rotate a "Loading" view displayed when the app is downloading content. (device orientation changes seem to fire at different times, causing the view that needs to respond to these events to rotate sporadically).
The app previously added a UINavigationController's view to the main window. I modified the hierarchy to add the view of a UIViewController subclass to the main window, and added the view of the UINavigationController to the subclass's view. The UIViewController subclass manages the display & rotation of the "Loading" subview, and I was expecting the rest of the app to continue behaving normally, as inserting one extra empty view into the hierarchy didn't feel like I was changing too much.
My initial problem was the positioning of the UINavigationController - it was 20 pixels too low, resulting in a gap between the status bar and the navigation bar, and cutting off the bottom 20 pixels of the tab bar. I was able to adjust this by setting the frame property of the UINavigationController's view to the bounds property of the UIViewController's view, which corrected the position.
However, now I'm stuck with a 20-pixel-high dark "overlay" on top of my navigation bar. If I were to guess, I'd say it was black with 50% opacity. Touch events on this bar don't work (e.g. if I try to tap the "Back" button through the overlay, nothing happens). The fact that the height is equal to that of the status bar hasn't escaped me, but I'm at a total loss as to what could be causing it.
I hate feeling this stupid, so if anyone has any insight into this problem, you'd really make my day. Thanks in advance!
OK, a few things pop out from your post.
My initial problem was the positioning of the
UINavigationController - it was 20
pixels too low
This makes me believe it is related to your new problem.
I was able to adjust this by setting
the frame property of the
UINavigationController's view to the
bounds property of the
UIViewController's view
This sounds like the view it was loaded onto was offset 20 pixels, and when you set it to the bounds, it repositioned it on the windows view space.
Touch events on this bar don't work
(e.g. if I try to tap the "Back"
button through the overlay, nothing
happens)
This is the big thing. If touch events aren't being sent to the view, then what that means is that the OS doesn't see a view where you are pressing (or rather the view you want it to), so that view doesn't get the message to do something.
From what you have said, I believe your problem is with your base view controller that you just added. Try redoing the frame on, making it conform to where you want. Then take out the code you put in to set the navigation controllers frame. The navigation controller should fit to the view you added too, and once you have that main view where it needs to be (20 pixels higher apparently), then everything should work.

tabBarController + changing orientation problem

I have a TabBarController with 4 views, and one of them is a scrollView. If i load this view, and then change the orientation of my device from portrait to landscape, the scrollview responds to the touches only 'till the pixel 320.
If later i go to another view, and then come back to the first, the scroll view works well even in landscape.
How can i adjust this?
Your scroll view is probably not set to automatically adjust its height and width. If your view is built with Interface Builder, use the Autosizing section of the Size Inspector to set the struts & springs. Otherwise, if you're building your view programmatically, you'll need to set the autoresizingMask property to something appropriate.

Tab views on iPad not resizing

My view doesn't stretch to fit the current orientation!
I am creating a tab bar application. I replicated the sample one that you create when you "create a new tab bar application". Everything works except when I change the orientation of the iPad it rotates the view, the tab bar stretches out on the bottom, but the view doesn't resize. Basically if you start in landscape then rotate to portrait, it rotates but the view is still landscape shape even though it rotates.
My tab bar has two tabs (just like the sample application) and so I compared mine against the sample which works property by property. One difference is I noticed my FirstView in IB under the resizing area doesn't show the resize arrows left/right up/down. In other words it isn't marked to auto fill its container. The sample's FirstView and SecondView DO have these arrows. But I can't turn them on!
I even tried creating a fresh new view but I still can't press these arrows on. what am I doing wrong here?'
Thanks a lot.
The solution is this:
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Do this in viewDidLoad. There must be a bug in IB.
Another answer is turning off any simulated tabbars, nav bars, or status bars on the view in Interface Builder. Go into the autosizing area and turn on the auto grow arrows. Then turn back on the simulated user elements.