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

时间:2012-01-11 20:17:28

标签: 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]
    //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。如何在设备旋转时将标志更改为YES。看起来微不足道,但似乎无法弄明白。

我尝试在UIDevice中注册devicechnagenotification但是没有用。任何方向的BOOL都是YES。苹果的例子使用了这个,但看起来这不是正确的方法。

1 个答案:

答案 0 :(得分: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;
 }