Iphone方向和2个笔尖文件 [英] Iphone Orientation and 2 Nib Files

查看:114
本文介绍了Iphone方向和2个笔尖文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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).

这是我的定位方法:

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

}

推荐答案

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.

这篇关于Iphone方向和2个笔尖文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆