将UIView添加到横向窗口中

时间:2014-05-02 11:43:56

标签: objective-c uiview uiviewcontroller uisplitviewcontroller landscape

我的应用程序以UISplitViewController开始,之后我想从故事板上的UIViewController显示另一个UIView。所以我在-viewWillAppear中调用了这个函数:

-(void)showSplashScreen{

    UIView *splashView;
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];


        UINavigationController *splashVC = [self.storyboard instantiateViewControllerWithIdentifier:@"splashscreen"];

        splashView = splashVC.view;

        NSLog(@"height: %f", splashVC.view.frame.size.height);
        NSLog(@"width: %f", splashVC.view.frame.size.width);


        NSLog(@"self view height: %f", self.view.frame.size.height);
        NSLog(@"self view width: %f", self.view.frame.size.width);


    [appDelegate.window addSubview:splashView];


    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC),dispatch_get_main_queue(), ^{
        [UIView transitionWithView:appDelegate.window
                          duration:1.00f
                           options:UIViewAnimationOptionCurveEaseOut
                        animations:^(void){
                            splashView.alpha = 0.0f;
                        }
                        completion:^(BOOL finished){
                            [splashView removeFromSuperview];
                        }];
    });

}

UIView始终以纵向模式显示。我将故事板中的所有内容都设置为横向模式。该应用程序从横向开始。只允许景观。当然没有像以下那样的功能: [self.storyboard instantiateViewControllerWithIdentifier:@“splashscreen”inPortrait:False]; 我猜对开发人员来说很容易....

那么,有人有想法吗? (当然我可以添加启动图像,或者我可以在UISplitViewController之前加载UIViewController ......)但是它也应该像这样工作吗?

2 个答案:

答案 0 :(得分:1)

-(void)showSplash{

    UIView *splashView;
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName: IS_IPAD ? @"Main_iPad" : @"Main_iPhone" bundle:nil];
    UINavigationController *splashVC = [storyboard instantiateViewControllerWithIdentifier:@"splashscreen"];
    splashView = splashVC.view;


    splashView.frame = IS_IPAD ? self.splitViewController.view.bounds : appDelegate.window.bounds;

    IS_IPAD ? [self.splitViewController.view addSubview:splashView] : [appDelegate.window addSubview:splashView];


    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC),dispatch_get_main_queue(), ^{
        [UIView transitionWithView: IS_IPAD ? self.splitViewController.view : appDelegate.window
                          duration:1.00f
                           options:UIViewAnimationOptionCurveEaseOut
                        animations:^(void){
                            splashView.alpha = 0.0f;
                        }
                        completion:^(BOOL finished){
                            [splashView removeFromSuperview];
                        }];
    });

}

答案 1 :(得分:0)

这可能会对您有所帮助:

UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    switch (interfaceOrientation) {
        case UIInterfaceOrientationLandscapeLeft:
            self.transform = CGAffineTransformMakeRotation(M_PI * 270.0 / 180.0);
            break;

        case UIInterfaceOrientationLandscapeRight:
            self.transform = CGAffineTransformMakeRotation(M_PI * 90.0 / 180.0);
            break;

        case UIInterfaceOrientationPortraitUpsideDown:
            self.transform = CGAffineTransformMakeRotation(M_PI * 180.0 / 180.0);
            break;

        default:
            break;
    }
    [self setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];