【问题标题】:masterView does not always show/hide properlymasterView 并不总是正确显示/隐藏
【发布时间】:2012-01-11 20:17:28
【问题描述】:

我有一个 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。苹果示例使用了这个,但看起来这不是正确的方法。

【问题讨论】:

  • 为什么不使用Split View控制器委托方法- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
  • 我正在使用它。我没有提到那里。道歉。我为这个委托方法返回了 NO。
  • 如果你总是为那个方法返回YES会发生什么?
  • 我希望主视图显示任何方向旋转。所以返回 YES 对我来说不是一个选择。但是,返回 yes 也有相反的问题。当主视图可见 + 设备方向发生变化时,详细视图会将主视图的宽度向左滑动。
  • 对于拆分视图控制器来说,这是一个非常奇怪的行为。我有一个基于最新 Xcode 的主细节模板的拆分视图控制器的简单项目,它完美地工作。我不确定是什么导致了您描述的这种行为。

标签: objective-c ios ipad


【解决方案1】:

好的,我终于想出正确设置标志以更改方向。我添加了以下方法

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    相关资源
    最近更新 更多