如何在二级实现SplitViewController。

时间:2011-10-19 04:53:26

标签: ios ipad

如何在二级实现SplitViewController。

实际上我想要的是使用登录页面和登录后启动应用程序。我需要SplitViewController。

2 个答案:

答案 0 :(得分:0)

我就是这样做的。从窗口中删除第一个viewContorller并将其替换为splitView

 splitViewController = [[SplitViewController alloc]init];
    // remove the current view and replace with splitViewController
    [theWindow addSubview:splitViewController.view];

    // Transition handling
    NSString *subtypeDirection;
    switch ([[UIApplication sharedApplication] statusBarOrientation]) {
        case UIDeviceOrientationPortrait:subtypeDirection = kCATransitionFromRight;break;
        case UIDeviceOrientationPortraitUpsideDown:subtypeDirection = kCATransitionFromLeft;break;
        case UIDeviceOrientationLandscapeLeft:subtypeDirection = kCATransitionFromTop;break;
        case UIDeviceOrientationLandscapeRight:subtypeDirection = kCATransitionFromBottom;break;
        default: NSLog(@"break at subType direction");break;
    }

    CATransition *animation = [CATransition animation];
    [animation setDuration:.5];
    [animation setType:kCATransitionPush];
    [animation setSubtype:subtypeDirection];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [[theWindow layer] addAnimation:animation forKey:@"SwitchToSplitView"];

    [self.navigationController.view removeFromSuperview];

这里的大多数线都涉及过渡和处理轮换。

self指的是第一个ViewController,而theWindow指的是应用程序窗口。您可以通过以下方式访问它:[self superView];

答案 1 :(得分:0)

对于相同的登录 - > splitview控制器我正在做以下事情:

一个。子类UIStoryboardSegue并覆盖perform

@implementation SSPushSegue

- (void)perform
{
    UIWindow* window = [self.sourceViewController view].window;

    // Transition handling
    NSString *subtypeDirection = kCATransitionFromRight;
    switch ([UIApplication sharedApplication].statusBarOrientation)
    {
        case UIDeviceOrientationPortraitUpsideDown: subtypeDirection = kCATransitionFromLeft; break;
        case UIDeviceOrientationLandscapeLeft: subtypeDirection = kCATransitionFromTop; break;
        case UIDeviceOrientationLandscapeRight: subtypeDirection = kCATransitionFromBottom; break;
        default: break;
    }

    CATransition *animation = [CATransition animation];
    animation.duration = .5;
    animation.type = kCATransitionPush;
    animation.subtype = subtypeDirection;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [window.layer addAnimation:animation forKey:NSStringFromClass([self class])];

    window.rootViewController = self.destinationViewController;
}

@end

湾将“自定义Segue”从“初始视图控制器”添加到“目标”,并将您的子类名称放在属性字段中。