Changing parameters on iOS device orientation - iphone

I have a Tabbar project in which one one the tabs should be on landscape mode. I've seen than the Tabbar controller only allows it only if all its views allow it. Son now I'm somehow forced to adapt all the views for both portrait and landscape mode, which I've never did before.
Am I right assuming that all should be done under:
-(void)willAnimateRotationToInterfaceOrientation...
so what happens with subview which are lazyly initialized? such as a footerView on a tableView?
Another thing is, I have a method to scroll the tableView so nothing is kept under the keyboard when it's called. The method uses a constant float + a variable. In landscape mode, the constant should be another.
Any feedback would be appreciated. Thanks in advance!

Read up on autoresizingmask - setting this attribute on your views will automate a lot of the orientation resizing.
And yes, you'll need a landscape and a portrait value for your constant.

Related

Iphone View Rotation not functioning properly

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.

Iphone sdk custom uiview orientation issue

I am using custom based uiview controller with uitabbar contains uitableview. I am using image for cell background. I want to do orientation from portrait to landscape but the issue is it is not changing on orientation. I just want to know is there are any special thing for custom uiviewcontroller for orientation?
Thanks in advance
Regards,
sathish
If nothing happens when you rotate the device, you either have the system-wide rotation lock enabled (you checked that, right?), or your view controller isn't returning YES to the alternate orientation in its shouldAutorotateToInterfaceOrientation:, or you're doing something odd with your views that means your view controller isn't getting set as the “frontmost” one and thus isn't getting asked about orientation changes. It'll be easier to narrow that down if you post the code you're using to set up the controller and its view.

UILabels don't look good in the landcsape mode

I am writing a game in the landscape mode. In *.plist I've set the "Initial interface orientation" option to "Landscape (left home button)". In Interface Builder my form seems good, with 2 labels are on the left and bottom.
But when I launch the app in simulator or in iphone that looks like the following
http://www.glowfoto.com/static_image/07-102041L/8907/png/09/2010/img4/glowfoto
Labels are on the top and rotated. Anyone knows what I am doing wrong and how to solve this?
I think your view controller's shouldAutorotateToOrientation method is not returning YES to landscape but to portrait orientations. But without code it's a guess in the wild.

Difficulty with apps with a forced landscape orientation

I have two apps, both of which force the user to use the iPhone in landscape mode, in order to have a wider screen, instead of a taller one.
One of the things I have found is that my first view will look fine, but all other views come up with their subviews (UIButtons, UIPicker, UIViews) squeezed to one side or clipped (depending on whether the elements were set to move, resize or stay in the same position as the view size changed). All my views are designed in IB in the landscape orientation. My underlying UIWindow, and everything I can think of has been laid out in landscape orientation. Even my plist file has the UIInterfaceOrientationLandscapeRight flag set.
Now, if I load all my views at the same time as my rootview controller, then I have no problems. But if I have views loaded later, they get clipped or squeezed.
The only way to get around the problem was to add the following line in my code that flips in a new view:
[coming.view setFrame:CGRectMake(0, 0, 480, 300)];
Anyone know why I need to do this? Is it just that the iPhone assumes that loaded views are 300x480 unless a transform gets applied to them?
Thanks.
ps. This is what the view looks like if I don't call setFrame, as described above:
alt text http://files.me.com/mahboud/ljhvun
All viewcontrollers that get loaded after the first one will have their screen similarly squeezed down. For some reason the first viewcontroller doesn't have this issue.
I think you want to use landscape mode in each single view in your app. And you want the nib to be landscape mode too. You can resize the view to (0,0,480,300 for statusbar, 320 for non-statusbar) in nib. And design what you want. Finally, in view controller return no for autorotate. And finally transform the view and rotate.
I had a similar problem, asked the question on SO, and then figured it out and answered it myself. You may want to check it out.
A proper answer will depend on knowing how you are forcing landscape orientation. If you are doing this through UIViewController and company, it should be relatively simple; for other methods probably more complex.
In the simple case, you should be able to override shouldAutorotateToInterfaceOrientation: on your view controller, setup your views in Interface Builder, and set the UIInterfaceOrientation key to UIInterfaceOrientationLandscapeRight in your Info.plist and be set.
A simple way I fixed this was to have my root view controller subclass UINavigationController, and implement shouldAutorotateToInterfaceOrientation to handle landscape view ie,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
Every view controller that is pushed to the navigation controller seems to appear in landscape too.

iPhone autorotation only on specific screens in under a navigation controller

This is just an example of the basic problem I'm having, so don't worry if this situation sounds a bit pointless ;)
Let's say I have an app that's mainly a UINavigationController just two levels deep. The top level is a table with a list of image filenames, and the second level has just a UIImageView showing the image for the filename you tapped.
For an app such as this, does anyone know a good way to allow the table at the top level to autorotate while keeping the second level of images fixed in portrait mode?
So far I've been able to almost get there... but when I tap a filename while in landscape mode, the image slides into view in the wrong orientation even if the second level view controller's shouldAutorotateToInterfaceOrientation returns yes for only portrait modes.
There was no good way to do this in iPhone OS 2.x, but in 3.0, they've dramatically improved it.
In 2.x, the shouldAutorotateToInterfaceOrientation: delegate method was only obeyed for changes to the orientation, so you'd get the behavior you describe: if it was rotated in another view controller, it would stay rotated through pushes and pops even if the new view controller didn't support rotation to that orientation.
In 3.0, UINavigationController polls shouldAutorotateToInterfaceOrientation: on each push or pop and obeys what it returns the way you'd expect, e.g.: if you're currently rotated in Landscape Left orientation, and you push an instance of a view controller that only supports Portrait orientation via shouldAutorotateToInterfaceOrientation:, it automatically and instantly flips the logical orientation and slides in the new view the correct way in Portrait orientation.
Note that this will only work on applications linked against (and therefore requiring) 3.0. For applications linked against 2.x, it will emulate the old behavior.
The problem is that if you use auto rotation the entire UI (including the UIWindow instance I believe) is rotated.
Anything pushed onto the navigation controller at this point will be done in landscape.
So when you push the imageview, that is exactly what you get.
To get this to work, you have to either:
Handle the rotation of the root view
manually (using a transform)
Unrotate the image view by -PI/2
using a transform.
Either way you have to perform the transforms manually to get this to work.
As a side note, this may be bad UI design. As a user, I would expect as I drill down for images to appear rightside up. But this is without knowing the exact context of your app.