Objective c 主视图并不总是正确显示/隐藏

Objective c 主视图并不总是正确显示/隐藏,objective-c,ios,ipad,Objective C,Ios,Ipad,我有一个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

我有一个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;
}
一切几乎都按预期进行。 问题:在一个方向中,&&master不可见。。然后设备改变方向。。主视图没有从屏幕上滑出,而是将细节视图推到了另一个方向。我知道这是因为现在的标志设置为masterIsVisible=NO而不是YES。如何在设备旋转时将标志更改为“是”。看起来微不足道,但似乎无法理解


我试着在UIDevice中注册devicechnagenotification,但没有成功。在任何方向上,布尔都是肯定的。苹果的例子使用了这个方法,但看起来这不是正确的方法

好的,我终于找到了正确设置方向改变标志的方法。我添加了以下方法

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

为什么不使用拆分视图控制器委托方法
-(BOOL)拆分视图控制器:(uiplitviewcontroller*)svc应使用IDEVIEWController:(UIViewController*)vc inOrientation:(UIInterfaceOrientation)orientation
?我正在使用它。我上面没有提到。道歉。我为此委托方法返回了“否”。如果始终为此方法返回
YES
,会发生什么情况?我希望主视图显示任何方向旋转。所以我不能选择返回YES。然而,返回yes也有同样的问题。当主视图可见+设备方向改变时,局部视图会向左滑动主视图的宽度。对于拆分视图控制器来说,这是一种非常奇怪的行为。我有一个基于最新Xcode的主细节模板的带有拆分视图控制器的裸体项目,它可以完美地工作。我不确定是什么导致了你描述的这种行为。