Splitview Orientation问题。(人像模式)

时间:2013-06-05 11:22:21

标签: ios ipad ios6 orientation uisplitviewcontroller

背景

我有一个iPad splitview应用程序。拆分视图是窗口的根视图控制器。我需要一个应用程序的登录屏幕,因此我这样呈现:[self.splitViewController presentViewController:self.loginView animated:NO completion:nil];。我在主人身上有一个弹出窗口视图锚定到导航栏UIBarButtonItem,这有助于用户注销。这是工作gr8。

问题

我需要支持两个方向,因此主视图也必须以纵向模式显示。我遇到的第一个问题是当用户以纵向模式退出应用程序时,主视图不会被解除,当主视图仍然可见时,将显示登录视图。我设法通过复制左侧栏按钮上的点击事件来解决此问题,如下所示:

[self.detailViewController.navigationItem.leftBarButtonItem.target performSelector:self.detailViewController.navigationItem.leftBarButtonItem.action]; 

这引起了第二个问题。当我退出时,上面的代码片段正确地解除了主视图并且看到了loginview。但是现在如果我将我的方向更改为横向并再次登录,则主视图将被替换为一个黑色条带(宽度与masterview相等)。我认为splitview仍然认为它在portarit视图中并且方向更改没有传播到splitviewcontroller 。任何人都可以帮我解决这个问题。

到目前为止我做了什么

我尝试在详情视图中使用更新后的方向明确调用-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration,但它无效。

我将应用程序的rootview控制器重置为在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中创建的同一个splitviewcontroller实例,希望这可以作为刷新但不注意。

我不知道从哪里开始。重要说明:我在iOS 6.0上。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我通过改变主视图的原点来修复它

- (void)showMasterView
{
    if (!self.masterIsVisible)
    {
        self.masterIsVisible = YES;
        NSArray *controllers = self.splitViewController.viewControllers;
        UIViewController *rootViewController = [controllers objectAtIndex:0];

        UIView *rootView = rootViewController.view;
        CGRect rootFrame = rootView.frame;
        rootFrame.origin.x += rootFrame.size.width;

        [UIView beginAnimations:@"showView" context:NULL];
        rootView.frame = rootFrame;
        [UIView commitAnimations];
    }
}

- (void)hideMasterView
{
    if (self.masterIsVisible)
    {
        self.masterIsVisible = NO;
        NSArray *controllers = self.splitViewController.viewControllers;
        UIViewController *rootViewController = [controllers objectAtIndex:0];

        UIView *rootView = rootViewController.view;
        CGRect rootFrame = rootView.frame;
        rootFrame.origin.x -= rootFrame.size.width;

        [UIView beginAnimations:@"hideView" context:NULL];
        rootView.frame = rootFrame;
        [UIView commitAnimations];
    }
}

这只会在纵向模式下进行。 Thanks to...

PS:对于之前没有发布此答案表示诚挚的歉意。问题解决后我完全忘了它。现在修补我的错误:)

相关问题