2010-02-08 46 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

這是從蘋果公司的文件(視圖控制器編程指南):

標籤欄控制器和視圖旋轉

標籤欄控制器支持畫像 方向默認情況下並沒有 旋轉到橫向 除非所有的根視圖控制器都支持 方向。當設備方向發生更改時,標籤欄控制器 將查詢其視圖控制器數組。 如果其中任何一個不支持 的方向,則標籤欄 控制器不會更改其方向 。

因此,我不確定選項卡欄控制器是否設計爲僅爲單個視圖旋轉。

相關問題