2010-02-08 80 views
0

如何在旋转iphone(更换笔尖)时更改视图。 但它应该只发生在一个单一的标签! 我试了一下:仅在Tabbar-Application(横向纵向)中的一个选项卡上更改视图?

- (void)viewDidLoad { 
LandscapeViewController *viewController = [[LandscapeViewController alloc] 
      initWithNibName:@"LandscapeView" bundle:nil]; 
self.landscapeViewController = viewController; 
[viewController release]; 

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) 
      name:UIDeviceOrientationDidChangeNotification object:nil]; } 

- (void)orientationChanged:(NSNotification *)notification 
{ 
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0]; 
} 

- (void)updateLandscapeView 
{ 
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView) 
{ 
     [self presentModalViewController:self.landscapeViewController animated:YES]; 
     isShowingLandscapeView = YES; 
    } 
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView) 
{ 
     [self dismissModalViewControllerAnimated:YES]; 
     isShowingLandscapeView = NO; 
    }  
} 

但随后的景观,景观出现在所有选项卡。 (当这个代码加载一次)。 有什么想法?

回答

0

坦克为您的意见!我发现了一个解决方法:

//Remove Observer if not in Landscape 
- (void)viewDidDisappear:(BOOL)animated { 
    if (isShowingLandscapeView == NO) { 
     [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; 
    } 
} 

//Add Observer if not in Landscape 
- (void)viewDidAppear:(BOOL)animated { 
    if (isShowingLandscapeView == NO) { 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
    } 
} 
0

发生了什么事是您的视图控制器正在接收UIDeviceOrientationDidChangeNotification通知,无论是否显示旋转改变。请尝试使用UIViewController的内置方法来响应旋转。

http://tinyurl.com/ycb8of2

0

这是从苹果公司的文件(视图控制器编程指南):

标签栏控制器和视图旋转

标签栏控制器支持画像 方向默认情况下并没有 旋转到横向 除非所有的根视图控制器都支持 方向。当设备方向发生更改时,标签栏控制器 将查询其视图控制器数组。 如果其中任何一个不支持 的方向,则标签栏 控制器不会更改其方向 。

因此,我不确定选项卡栏控制器是否设计为仅为单个视图旋转。

相关问题