2011-02-08 98 views
0

我的應用程序是基於導航的。iPhone設備方向問題

所有視圖都顯示縱向模式,但報告模式除外。報告模式顯示橫向模式,當設備旋轉橫向時。

如果設備正在旋轉橫向模式報告視圖正在顯示橫向模式。如果報告爲橫向模式,則再次在設備中旋轉縱向模式將顯示當前視圖的正常視圖。

當前操作的流程我的視圖顯示。 從當前視圖是肖像模式,我在橫向模式下旋轉設備,因此獲取報告模式的橫向模式。兩次旋轉後,我只能以縱向模式獲取當前視圖。我需要減少兩次旋轉。請指導我。如果再次旋轉,如何檢查報告之後的橫向模式的條件,我需要在縱向模式下顯示當前視圖。

Here at ReportViewController 


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 

    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 

} 

@interface CurrentViewController 

BOOL isShowingLandscapeView; 
Report *landscapeViewController; 

@implementation CurrentViewController 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    Report *viewController = [[Report alloc]initWithNibName:@"Report" 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 == UIInterfaceOrientationPortrait && isShowingLandscapeView) 
    { 
     [self dismissModalViewControllerAnimated:YES]; 
     isShowingLandscapeView = NO; 
    }  
} 



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); // support only portrait 

} 

回答

0

我不知道我理解你的問題,但代碼看起來像它可能會顛倒邏輯。 在ReportViewController,

- (BOOL)shouldAutorotateToInterfaceOrientation 

旋轉之前調用,所以應該 回報是用於人像(YES,允許視圖從橫向到縱向旋轉) 和景觀返回NO(不,不要允許視圖旋轉到風景風景)。

而且同樣在CurrentVC - 嘗試

return (interfaceOriention==UIInterfaceOrientationLandscape); 

希望有所幫助。 -Mike

+0

不可能返回(interfaceOriention == UIInterfaceOrientationLandscape); UIInterfaceOrientationLandscape沒有檢查條件。只有可能的左或右和Islandscape。 updateLandscapeView方法當我檢查肖像模式 if(UIDeviceOrientationIsPortrait(deviceOrientation)&&!isShowingLandscapeView) 當前視圖爲縱向和旋轉設備它是當前視圖爲橫向和旋轉,報告視圖是橫向和旋轉當前視圖爲縱向。我需要當前視圖如果旋轉設備報告視圖爲橫向並旋轉當前視圖爲縱向,則視圖爲縱向。 – SOF 2011-02-13 16:46:06