I have a UIScrollView which contains a view controller which contains a couple of contorllers – text fields, buttons, an image, etc…
When it is shown on portrait mode, I want it to act as if there is no scroll view ( its still there, of course, but disabled scrolling and bouncing and etc, content size is application frame’s size ), and the custom view is just displayed normally, but when switching to landscape I want to make the scroll view available to use in order to avoid tight user interface.
I want to use a specific xib file for portrait/landscape modes and not place the objects differently using code, because of localization reasons
I encountered 3 problems doing this:
1)I cant find a way to load and apply to the controller a different xib when rotating ( I’d like it to be a smooth transition as well, but not as important right now )
2)I can’t find a way to set up something beyond the application frame’s in a xib file ( I dont have the buttons and etc directly in a scroll view, but inside a custom view which is inside a scroll view ), So I cant place anything on the invisible part of the scroll view ( the part that needs to be scrolled into in order to be seen )
3)I cant find a way to specify a scroll view’s content size via a xib file, which is needed in order for the interface to be as flexible as possible for localization.
Do you have any ideas on how to implement/solve these needs?
Thanks in advance!
I would advise doing the first thing you said you wouldn’t do:
I have spend a good amount of time trying to use a different XIB for different orientation but here is the deal:
1) If you have an UITextField in Portrait, when you rotate to landscape, you have to be sure that the text in portrait mode is the same in landscape, for example. You have to do that for every object.
2) Even if you dont look to point 1) I was never able to implement the two xibs solution successfully. I am not saying you cant do it, I am just saying from my experience, that I could not achieve that.
So, if you at least think doing the 1 xib solution, I could explain a bit:
//Create the frame for your “oneOfmyViews” for the portrait rotation
oneOfMyviews.frame=CGRectMake(…,….,…,…);
}
//Create the frame for your “oneOfmyViews” for the landscape rotation
oneOfMyviews.frame=CGRectMake(…,….,…,…);
You could then in the viewsPosition methods define your view’s frames. What you win?
1) Clean code.
2) Beautiful transitions.
3) Specify your scroll view’s content size easily.
For you problem with the rotation of your UIViews => CustomViewController => UIScrollView.
You can do something like this:
1) Do exactly the same thing in your custom view (methods above) for your UIViews inside your CustomViewController.
2) In the view that has your CustomViewControllers you can do the following:
This way you will make the UIViews inside your customViewController rotate. One last tip: disable autoresize-subviews and take out every auto-sizes from your UIViews (because you will be defining their frame individually).