I have a scroll view with 2 different subviews for two different orientation.
In portait mode, it shows a table view and in portait it shows the UIImageVie开发者_如何学Pythonw. I want to know the ideal way to handle the orientation. I am having glitches with my current way of handling 1.Load a view,and add scrollview as a subview to the root view. 2.Change orientation, 3.Change the frame and contents of the scrollview. 4.Add this modified scrollview as subview again.But, every time I change orientation,the new view gets added on top of the previous one.
If you want to have two different views for different orientations, you need to switch them while orientation is changing.
When you go from portrait to landscape, you have to remove UIImageView and add scrollview (and vice versa)
[myImageView removeFromSuperview];
[self.view addSubview:scrollView];
You can also check if view doesn't have a superview to be sure that you have to add it:
if(scrollView.superview == nil)
[self.view addSubview:scrollView];
As you have already added scrollView as subView so you do not need to add it as subView again. Just change the frame and contentSize of scrollView.
for Views do as
[scrollView.subView removeFromSuperView]
[scrollView addSubView:view1]; // or add view2
精彩评论