Iphone 方向和 2 个笔尖文件

发布于 2024-10-06 08:37:08 字数 642 浏览 0 评论 0原文

我正在尝试制作一个应用程序,其中每个视图控制器(.h/.m)都有 2 个 NIB 文件...一个用于纵向,一个用于横向。这是支持方向的“标准”方式还是我必须以编程方式手动设置方向视图?我面临的问题是,当用户翻转方向时,所有视图都会重置(因此用户必须重新输入文本字段/视图输入)。

这是我的定位方法:

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];

if(portrait) {
    [[NSBundle mainBundle] loadNibNamed:@"myview-portrait" owner:self options:nil];
    [self setupLayout];
} else{
    [[NSBundle mainBundle] loadNibNamed:@"myview-landscape" owner:self options:nil];
    [self setupLayout];
}

[UIView commitAnimations];

}

I am trying to make an app where each view controller (.h/.m) has 2 NIB files... one for portrait, one for landscape. Is this the "standard" way of supporting orientation or must I manually set up the orientation view programmatically? The problem I am facing is that when a user flips the orientation, all views are reset (so the user must re-enter text fields/views input).

Here is my orientation method:

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];

if(portrait) {
    [[NSBundle mainBundle] loadNibNamed:@"myview-portrait" owner:self options:nil];
    [self setupLayout];
} else{
    [[NSBundle mainBundle] loadNibNamed:@"myview-landscape" owner:self options:nil];
    [self setupLayout];
}

[UIView commitAnimations];

}

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

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

发布评论

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

评论(1

恋竹姑娘 2024-10-13 08:37:08

Apple 在其视图控制器编程指南中标题为“管理视图控制器的界面方向”的部分中提供了许多支持多种方向的不同建议。您可能想阅读该部分,看看他们的建议是否更适合您的需求。

话虽这么说,我已经在应用程序中使用了您上面介绍的策略,并且它似乎工作得很好。

为了解决视图“重置”的问题,我建议您在用户从一个控件移动到另一个控件时保留对用户输入的数据的引用。然后,当您的方向发生变化时,您可以重新填充控件,这样用户的“进度”就不会丢失。

Apple has a number of different suggestions for supporting multiple orientations in their View Controller Programming Guide in the section titled "Managing a View Controller’s Interface Orientation". You might want to read that section to see if any of their suggestions would better suit your needs.

That being said, I have used the strategy you have presented above in an application and it seemed to work pretty well.

To solve your problem of the views being 'reset' I would suggest that you keep a reference to the data being entered by the user as they move from control to control. Then when your orientation changes, you can repopulate the controls so the user's 'progress' isn't lost.

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