Rotation problems, managing subviews in a custom TabBarController
I am implementing a custom TabBarViewController
, that apart from the design should have the same behavior.
I manage my subViewControllers
in an array, initializing views with lazy loading as described in "Beginning Iphone Development" Chapter 6, which I do by filling my array with as many NSNull
objects as tabs I have and replacing them with freshly initialized viewControllers
when needed.
This way I can keep track of the right order of views and associating them with the right tabs (the first place in the array is reserved for the first view etc).
When switching views, the current view is removed with [currentViewController.view removeFromSuperview];
and a new one is added with [self.view addSubview:newViewController.view];
. The now former view i开发者_运维问答s preserved in the array for future use.
A difficulty arrises when rotating the device, because (I think) the viewControllers
in my array that are not added to the superview at that moment with addSubview
are not being rotated, which kind of makes sense, I guess.
The result is that when after rotation, e.g. to landscape mode, the user switches to a view that he has already been before, which is because of that already initialized, the view is presented to him still in portrait mode.
My questions are then:
1) Do I have to rotate my non-added subviews manually and if so, how is this done easiest?
2) How does the normal TabBarController
manage its controllers, in other words, am I doing it right?
Why dont you try changing the frame of your view controller's view property for the current mode that the user is in (Potrait or landscape)
So in shouldAutoRotateToInterfaceOrientation just change yourviewcontroller.view.frame = CGRectMake(x,y,width,height) and perhaps you will have your rotated views!!
I hope it helps
精彩评论