具有前视图的主/细节项目

时间:2013-06-07 11:38:17

标签: iphone ios ipad ios5 uisplitviewcontroller

我需要创建一个拆分视图应用程序,它以我手动定制的基本视图开始。然后我需要转换到SplitView或将主/详细信息表视图推送到堆栈以进行电话实现。

我计划使用的策略是将基本视图放在SplitView控制器的详细信息窗格中,当它在那里时,只需隐藏左窗格的侧面板和按钮,它们各自的方向。

有更好的方法吗?我可以使用“普通”视图作为我的根视图,然后以编程方式将其切换到UISplitView吗?

对于手机版 - 这不是一个真正的问题。由于导航控制器是根视图控制器 - 我可以将更多视图推送到堆栈。

对于iPad - 您无法将UISplitView控制器推入导航堆栈。我真的很想这样做,所以我有一些“背”的概念。我可以通过编程方式创建它 - 但在我做之前 - 如果它们存在,我会对其他一些选项感兴趣。

我想将Storyboard用于此应用程序 - 目标版本为iOS 5 - 用于ARC。

2 个答案:

答案 0 :(得分:1)

我通过替换应用程序的根目录来完成此操作。作为第一个屏幕,我有一个LoginViewController,当登录成功时,将ViewControllerUISplitViewController切换。你也可以做动画。

修改

以下是UIStoryboardSegue子类的代码:

- (void) perform
{
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

    UIViewController *sourceViewController = (UIViewController *)self.sourceViewController;
    UISplitViewController *destinationViewController = (UISplitViewController *)self.destinationViewController;

    UIWindow *window = appDelegate.window;
    window.rootViewController = destinationViewController;
    window.rootViewController = sourceViewController;

    [UIView transitionWithView:sourceViewController.view.window
                      duration:0.5
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    animations:^{
                        window.rootViewController = destinationViewController;
                    }
                    completion:^(BOOL finished){
                    }];
}

答案 1 :(得分:1)

试试这段代码: 您可以在Delegate

中将LoginViewcontroller添加为根视图控制器
   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {


        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        self.viewController = [[LogInViewController alloc] initWithNibName:@"LogInViewController" bundle:nil];


         self.window.rootViewController = self.viewController;

           [self.window makeKeyAndVisible];
        return YES;

    }


and your loginButton Action:

    -(IBAction)loginclick:(id)sender
    {
         objAppdelegate = (yourProjectnameDelegate *) [[UIApplication sharedApplication]delegate];
         NSMutableArray *array = [NSMutableArray array];

                    HomeSpilitView = [[[UISplitViewController alloc] init]autorelease];

                    HomeMster = [[HomeSpilitViewController alloc] initWithNibName:@"HomeSpilitViewController" bundle:nil];

                    masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:HomeMster] autorelease];
                    HomeMster.title=@"Title home";
                    masterNavigationController.navigationBar.tintColor =[UIColor colorWithRed:255/255.0 green:108/255.0 blue:61/255.0 alpha:0.1];
                    [array addObject:masterNavigationController];


                    HomeDetailsViewController *HomeDetailsViewControllers = [[HomeDetailsViewController alloc] initWithNibName:@"HomeDetailsViewController" bundle:nil];

                    detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:HomeDetailsViewControllers] autorelease];

                    detailNavigationController.navigationBar.tintColor =[UIColor colorWithRed:255/255.0 green:108/255.0 blue:61/255.0 alpha:0.1];
                    HomeDetailsViewControllers.title=@"details title";
                    HomeMster.objHomeDetailsViewcontroller=HomeDetailsViewControllers;
                    HomeSpilitView.delegate = HomeDetailsViewControllers;

                  [array addObject:detailNavigationController];

                  [HomeSpilitView setViewControllers:array];

                  [objAppdelegate.window setRootViewController:HomeSpilitView];


    }


//===for animation


     UIInterfaceOrientation interfaceOrientation = HomeSpilitView.interfaceOrientation;
        NSString *subtypeDirection;
        if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
            subtypeDirection = kCATransitionFromTop;
        }
        else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
            subtypeDirection = kCATransitionFromBottom;
        }
        else {
            subtypeDirection = kCATransitionFromRight;
        }
        [objAppdelegate.window setRootViewController:HomeSpilitView];
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.5];
        [animation setType:kCATransitionPush];
        [animation setSubtype:subtypeDirection];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

        [[objAppdelegate.window layer] addAnimation:animation forKey:@"SwitchToView1"];