2012-01-11 30 views
0

我有一個splitViewController。這是詳細VCmasterView並不總是顯示/隱藏

-(void)viewDidLoad 
{ 
    self.masterIsVisible = YES; 
    //a botton in navigation bar to hide or show the master view. 
    [button addTarget:self action:@selector(showOrHideMasterView) 
    forControlEventsTouchUpInside] 
    //gesture control to swipe right or left to slide master view in and out. 
    [swiperight addTarget:self action:@selector(showMasterView)]; 
    [swipLeft addTarget:self action:@selector(hideMasterView)]; 
} 

-(void)showOrHideMasterView 
{ 
if (self.masterIsVisible) 
    [self hidemasterView]; self.masterIsVisible = NO; 
else 
    [self showMasterView]; self.masterIsVisible = YES; 
} 

-(void)hideMasterView 
{ 
    //hides master view by substracting masterview's width from its origin.x 
} 

-(void)showMasterView 
{ 
    //shows master View by adding masterview's width to its origin.x 
} 
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:  (UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation 
{ 
    return NO; 
} 

一切幾乎按預期工作。 問題:在一個方向& &主是不可見..然後設備更改方向..主視圖,而不是滑出屏幕推動詳細視圖的另一種方式。我知道這是因爲現在標誌設置爲masterIsVisible = NO而不是YES。我可以做什麼來將設備旋轉時的標誌更改爲YES。看起來微不足道,但似乎無法弄清楚。

我試着在UIDevice註冊devicechnagenotification但沒有奏效。 BOOL在任何方向都是YES。蘋果的例子使用這個,但看起來像這不是正確的方法在這裏。

+0

你爲什麼不使用拆分視圖控制器的委託方法' - (BOOL)splitViewController:(UISplitViewController *)SVC shouldHideViewController:(UIViewController的*)VC inOrientation:(UIInterfaceOrientation)方向 '? – 2012-01-11 21:05:09

+1

我正在使用它。我沒有提到那裏。道歉。我爲這個委託方法返回了NO。 – yourAnswerIsAwesome 2012-01-11 21:15:50

+0

如果您始終爲該方法返回YES,會發生什麼情況? – 2012-01-11 21:26:15

回答

0

好吧,我終於想出正確設置方向改變標誌。我增加了以下方法

-(void)willAnimateRotationToInterfaceOrientation: 
    (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
if (toInterfaceOrientation == UIInterfaceOrientationPortrait) 
    self.masterIsVisible = NO; 
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    self.masterIsVisible = YES; 
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
    self.masterIsVisible = YES; 
else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    self.masterIsVisible = NO; 
}