2010-08-18 85 views

回答

1

你可能在你这样的事情,(我没有方便的Xcode所以这个代码可能不完全准确)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)){ 
WhatYourNewViewClassISCAlled* newView = [[WhatYourNewViewClassISCAlled alloc] initWithNibName:@"NIBNAME" bundle:[NSBundle mainBundle]]; 
[self.navigationController pushViewController:newView animated:YES]; 
} 
+0

但随后纵向方向看法仍然会在堆栈上,不是吗?所以后退按钮会指向错误的东西。 – 2010-08-19 18:09:12

+0

好点,你可以在视图旋转时隐藏导航栏,或者已经创建了视图并将其淡入,并在旋转发生时淡入其他视图。 – octermircty 2010-08-19 22:21:35

1

这是正确的做法,我相信。我在我的应用程序使用它,它完美的作品

  1. 触发上会旋转,(直到旋转阿尼姆即将开始等待)
  2. 用来横向/纵向文件苹果命名公约不应转动(为Default.png是默认-landscape.png如果你希望苹果自动加载的风景版)
  3. 重新加载新的NIB
  4. 其重置self.view - 这将自动更新显示
  5. ,然后它调用viewDidLoad(如果您手动重新加载NIB,Apple不会为您调用此函数)

(NB stackoverflow.com这里需要这句话 - 有代码格式错误)

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) 
    { 
     [[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@-landscape", NSStringFromClass([self class])] owner:self options:nil]; 

     [self viewDidLoad]; 
    } 
    else 
    { 
     [[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@", NSStringFromClass([self class])] owner:self options:nil]; 

     [self viewDidLoad]; 
    } 
}