2010-09-09 107 views
0

我只是想问问是否有其他人也有这个问题;风景视图显示何时不应该出现

它曾经是,默认情况下的TabBar的应用程序并没有让景观视野,除非它是在应用程序的所有视图中启用,但有可能会增加

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotateFromInterfaceOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 

赶方向变化信息&然后相应地对消息作出反应。

最近我已经看到,一旦显示了横向视图,每个不允许横向的视图将显示手机倾斜时的先前横向视图。

所以, 视图1(不支持横向)倾斜电话显示视图1横盘整理, 视图2(支持横向)倾斜电话显示Landscapeview2, 现在的山水景观已经显示一次, 视图1倾斜显示Landscapeview2

我在presentModalViewController后释放视图控制器,并在不再需要横向视图时关闭视图控制器,因此它应该消失,但在第一次显示后不断显示任何方向,就像再次调用presentModalViewController一样。

任何想法?任何其他人有相同的问题? (它从来没有发生过3.x操作系统版本)

回答

0

对于任何感兴趣的人; 看起来,视图控制器在视图控制器不再是活动视图时仍然作为观察者停留在方向变化中,基本上它正在回答每个视图的变化。

我的解决方案是创建2个新的BOOL,1个叫做isActiveView,1个叫做isShowingLandscape,并用它们来确保视图控制器只在它或它的横向视图被显示时才响应。

相关代码:

-(void)viewDidAppear:(BOOL)animated 
{ 
    isActiveView = TRUE; 
} 

-(void)viewDidDisappear:(BOOL)animated 
{ 
    isActiveView = FALSE; 
} 

-(void)didRotateFromInterfaceOrientation 
{ 
    if ((orientation == UIDeviceOrientationPortrait) && ((isActiveView) || (showingLandscape))) 
    { 
    [self dismissModalViewControllerAnimated:YES]; 
    showingLandscape = FALSE; 
    } 
    else if ((orientation == UIDeviceOrientationLandscapeLeft) && (isActiveView)) 
    { 
    LandscapeViewController *landscapeViewControllerObject = [[LandscapeViewController alloc] initWithNibName:@"LandscapeView" bundle:[NSBundle mainBundle]]; 
    [self presentModalViewController:landscapeViewControllerObject animated:YES]; 
    [landscapeViewControllerObject release]; 
    showingLandscape = TRUE; 
    } 
    else if ((orientation == UIDeviceOrientationPortraitUpsideDown) && ((isActiveView) || (showingLandscape))) 
    { 
    [self dismissModalViewControllerAnimated:YES]; 
    showingLandscape = FALSE; 
    } 
    else if ((orientation == UIDeviceOrientationLandscapeRight) && (isActiveView)) 
    { 
    LandscapeViewController *landscapeViewControllerObject = [[LandscapeViewController alloc] initWithNibName:@"LandscapeView" bundle:[NSBundle mainBundle]]; 
    [self presentModalViewController:landscapeViewControllerObject animated:YES]; 
    [landscapeViewControllerObject release]; 
    showingLandscape = TRUE; 
    } 
} 

希望这有助于任何人有同样的问题。