masterView并不总是显示/隐藏正确

我有一个splitViewController。 这是详细的VC

-(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。 苹果的例子使用这个,但在这里看起来不是正确的方法。

好吧,我终于想出正确的方向改变标志。 我加了下面的方法

 -(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; }