Iphone Orientation and 2 Nib Files

↘锁芯ラ 提交于 2020-01-22 20:00:09

问题


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

}


回答1:


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.



来源:https://stackoverflow.com/questions/4346597/iphone-orientation-and-2-nib-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!