如何让 UISegmentedControl 交换视图进出,并且仍然能够旋转方向?

发布于 2024-11-18 02:52:40 字数 1356 浏览 1 评论 0原文

我浏览了有关此主题的许多帖子,但无法解决我遇到的问题。我正在展示一个 UIViewController 模态视图。我已将该视图设置为在右上角有一个 UISegmentedControl,理想情况下,它允许我切换视图(在此模式视图内部)。

为了不遮盖顶部的工具栏,我在 IB 中制作了一个简单的 UIView,并布置了尺寸,以便它们不会与工具栏重叠。现在我的想法是,如果我在选择 UISegmentedControl 时添加我想要添加到 UIView 的视图,生活将会很棒:

-(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]];
}

}

这有效!但问题是,当我旋转设备时,我真正关心的视图(内部视图)不会旋转。

我尝试过不执行这种外部父 UIView 方法,只是尝试使用某个框架设置视图控制器视图,但方向仍然很混乱。

我也尝试使用 UINavigationController 执行此操作,只是不设置过渡动画,但我无法使其正常工作。

所以我的问题是:我该怎么办?!我想要的只是能够使用 UISegmentedControl 在视图之间切换,并能够将设备旋转到我需要的任何方向。我想了很多,尝试了很多不同的事情,我觉得我不知道发生了什么。

感谢您的帮助

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹎☆浅夏丿初晴 2024-11-25 02:52:40

好吧,经过更多研究后发现,我的调整大小蒙版在 IB 中设置不正确。卫生部!

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文