masterView并不总是正确显示/隐藏 [英] masterView does not always show/hide properly

查看:132
本文介绍了masterView并不总是正确显示/隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个splitViewController。这是详细信息VC

I have a splitViewController. This is in Detail 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。看起来微不足道,但似乎无法弄明白。

Everything almost works as intended. Problem: In one orientation && master is NOT visible.. then device changes orientation.. the master View instead of sliding off the screen pushed the detail view the other way. I know thats because the flag now is set as masterIsVisible = NO instead of YES. What can I do to change the flag to YES on device rotation. looks trivial but cant seem to figure out.

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

I tried registering for devicechnagenotification in UIDevice but that did not work. The BOOL is YES in any Orientation. The apple example uses this but looks like thats not the right approach here.

推荐答案

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

Ok, I finally figured out to set the flag correctly for orientation change. I added the following method

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

这篇关于masterView并不总是正确显示/隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆