iPhone 多视图旋转地狱

发布于 2024-12-13 12:20:36 字数 1714 浏览 2 评论 0原文

这是我在这里发表的第一篇文章,我对 iPhone 开发还很陌生,所以请耐心等待。

我有一个应用程序,它有几个视图控制器,每个视图控制器都有几个它控制的笔尖文件,并且一些笔尖有多个视图。整个应用程序中有一个工具栏,由根视图控制器控制。

经过大量搜索后,除了一个屏幕之外,我在每个屏幕上都可以进行旋转。我还没有让它们以正确的方向加载,但我想这是一个不同的问题。

在具有多个视图的笔尖中,我只能在原始主视图上选择自动调整大小选项。在我添加的视图(使用 insertSubview 加载)上,我可以选择固定边距选项,但不能选择宽度和高度调整大小选项。我正在使用 Xcode 4。

我的第一个问题是,为什么我无法在其他视图上选择调整大小选项?

抱歉,我必须删除我放在这里的图像,以显示我的意思,才能发布。

无论如何,这不是我的主要问题,出于好奇,我只是想知道为什么我无法选择调整大小选项。我在代码中找到了解决方法。在加载子视图的函数中,我添加 [viewName setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

例如,要加载我命名为 shiftStart 的视图,我使用:

- (IBAction)loadShiftStart:(id)sender {
    [self clearView];
    [self.view insertSubview:shiftStart atIndex:0];
    [shiftStart setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
}

现在这是我的问题。我有一个 nib 文件,有 3 个视图,view 是首先加载的主视图,rotaStart,当按下第一个视图上的按钮时,它作为子视图加载,shiftStart,当第一个视图上的按钮按下时,它作为子视图加载视图被按下。 rotaStart 和 shiftStart 几乎相同,都有标题、文本块、“是”按钮和“否”按钮。唯一的区别是框中的文本,以及单击“是”或“否”按钮时加载的视图。

我在 Xcode 中为标题、文本块和按钮选择了所有相同的调整大小和边距选项,据我所知,加载它们的代码是相同的(参见下面的代码),但 shiftStart 旋转正确,而 rotaStart 旋转正确不是。

- (IBAction)loadRotaStart:(id)sender {
    [self clearView];
    [self.view insertSubview:rotaStart atIndex:0];
    [rotaStart setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
}

- (IBAction)loadShiftStart:(id)sender {
    [self clearView];
    [self.view insertSubview:shiftStart atIndex:0];
    [shiftStart setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
}

谁能告诉我为什么当手机更改为横向时 rotaStart 不旋转?

抱歉这个解释有点啰嗦。我不知道还能如何解释。

谢谢

This is my first post on here and I'm very new to iPhone developing, so please bear with me.

I have an app which has a few view controllers and each view controller has a few nib files that it controls and some of the nibs have more than one view. There is a toolbar throughout the app, controlled by the root view controller.

After lot's of searching, I have got rotation working on every screen, except one. I haven't got them to load in the correct orientation, but I guess that's a different question.

In my nibs that have more than one view, I can select the autosizing options only on the original main view. On the views that I have added, which I load using insertSubview, I can select the fixed margin options, but not the width and height resizing options. I am using Xcode 4.

My 1st Question, is why I am unable to select the resizing options on the additional views?

Sorry, I had to delete the images I put in here, showing what I mean, to be able to post.

Anyway, that is not my main problem, I just want to know, out of curiosity, why I can't select the resize options. I have found a way around it in the code. In the function where I load the subview, I add [viewName setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

E.g to load the view that I have named shiftStart, I use:

- (IBAction)loadShiftStart:(id)sender {
    [self clearView];
    [self.view insertSubview:shiftStart atIndex:0];
    [shiftStart setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
}

Now here is my problem. I have a nib file that has 3 views, view which is the main view that loads first, rotaStart, which loads as a subview when a button on the first view is pressed and shiftStart, which loads as a subview when a button on the first view is pressed. rotaStart and shiftStart are almost identical, with a title, a text block, a Yes button and a No button. The only difference is the text in the box, and which view is loaded if you click on the Yes or No buttons.

I have all the same resize and margin options selected, in Xcode, for the title, text block and buttons and as far as I can tell, the code that loads them is identical (see code below), but shiftStart rotates correctly and rotaStart does not.

- (IBAction)loadRotaStart:(id)sender {
    [self clearView];
    [self.view insertSubview:rotaStart atIndex:0];
    [rotaStart setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
}

- (IBAction)loadShiftStart:(id)sender {
    [self clearView];
    [self.view insertSubview:shiftStart atIndex:0];
    [shiftStart setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
}

Can anyone tell me why rotaStart is not rotating, when the phone is changed to landscape please?

Sorry this explanation has got a bit long winded. I'm not sure how else to explain it.

Thanks

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

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

发布评论

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

评论(1

把回忆走一遍 2024-12-20 12:20:36

对于其他看到此问题并遇到类似问题的人,@longball 为我解决了这个问题。不知何故,我设法在基本视图的顶部添加了第二个视图,其中包含标签和视图。按钮。删除额外的视图解决了问题。

For anyone else looking at this, with a similar problem, @longball solved it for me. Somehow I had managed to add a second view over the top of the base view, complete with Labels & Buttons. Deleting the extra view fixed the problem.

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