开发者

How can I have a UISegmentedControl swap views in and out, AND still have the ability to rotate orientation?

I have looked around at a number of posts on this topic, but have been unable to fix the issues I am having. I am presenting a modal view that is a UIViewController. I've setup that view to have a UISegmentedControl on the top right that will ideally allow me to switch the view (inside of this modal view).

In order to not cover up my toolbar at the top, I have made a simple UIView in IB, and laid out the dimensions so they don't overlap the toolbar. Now my thinking is that if I add the view I want to add to the UIView when the UISegmentedControl is selected, life will be great:

-(IBAction) indexDidChangeForSegmentedControl:(UISegmentedControl*)seg{

int selectedNum = seg.selectedSegmentIndex;

if([[self.view1 subviews] objectAtIndex:0] != nil){
    [[[self.view1 subviews] objectAtIndex:0] removeFromSuperview];
}

if(selectedNum == 0){
    [self.view1 addSubview:[(DialogInfo*)[viewsArray objectAtIndex:seg.selectedSegmentIndex] view]];
}else if(selectedNum == 1){
    [self.view1 addSubview:[(DialogMetadata*)[viewsArray objectAtIndex:seg.selectedSegmentIndex] view]];
}else if(selectedNum == 2){
    [self.view1 addSubview:[(DialogVersions*)[viewsArray objectAtIndex:seg.selectedSegmentIndex] view]];
}else if(selectedNum == 3){
    [self.view1 addSubview:[(DialogAssoc*)[viewsArray objectAtIndex:seg.selectedSegmentIndex] view]];
}

}

And that works! But the problem is that when I rotate the device, the view that I really care about, the inner one, won't spin.

I have tried not doing this outer parent UIView approach, and just tried setting the view controller view with a certain frame, but the orientation is still messed up.

I have also tried doing this with a UINavigationController, and just not animating the transition, but I can't get that to work correctly.

So my question is: What do I do?! All I want is to be able to switch between views with a UISegmentedControl and be able to rotate the device to any orientation I need. I've thought through this so much and tried so many different things that I feel like I don't have a clue what is happening anymore.

开发者_运维百科Thank you for your help


Well it turns out after poking around some more that my resize mask wasn't set properly in IB. DOH!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜