本文介绍了使用Push Transition效果更改RootViewcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iOS应用程序中,我需要在app .so之间更改窗口的rootviewController,当我更改我的rootviewcontroller dyncamically它在更改之前轻弹视图。但我想要的是在rootviewcontroller更改时提供平滑过渡。

in my iOS App i need to change the rootviewController of the window in between of app .so when i change my rootviewcontroller dyncamically its flicking the view before its change.but what i want is to give a smooth transition when rootviewcontroller is changed.

我曾试过以下但不是我想要的过渡。

i had tried with the following but its not the transition i want.

[UIView transitionWithView:self.window
                      duration:.8
                       options:UIViewAnimationOptionTransitionCurlUp
                    animations:^{

                        self.window.rootViewController = tabBarControllerMain;
    [self.window makeKeyAndVisible];
                    }
                    completion:NULL];

我想要特定的转换,例如navigationcontroller pushview transition。

i want specific transition like navigationcontroller pushview transition.

任何机构都可以告诉我如何实现这一目标吗?

can any body give me idea how to achieve that?

推荐答案

UIViewController *viewControllerToBeShown=[[UIViewController alloc]init];

//viewControllerToBeShown.view.frame = self.view.frame;

viewControllerToBeShown.view.backgroundColor = [UIColor orangeColor];



AppDelegateClass *yourAppDelegate  =(AppDelegateClass*)[UIApplication sharedApplication].delegate;


UIView *myView1 = yourAppDelegate.window.rootViewController.view;

UIView *myView2 = viewControllerToBeShown.view;

myView2.frame = yourAppDelegate.window.bounds;


[yourAppDelegate.window addSubview:myView2];


CATransition* transition = [CATransition animation];
transition.startProgress = 0;
transition.endProgress = 1.0;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
transition.duration = 5.0;

// Add the transition animation to both layers
[myView1.layer addAnimation:transition forKey:@"transition"];
[myView2.layer addAnimation:transition forKey:@"transition"];

myView1.hidden = YES;
myView2.hidden = NO;


yourAppDelegate.window.rootViewController = viewControllerToBeShown;

Swift

        guard let appDelegate = UIApplication.shared.delegate,
            let appDelegateWindow = appDelegate.window,
            let appDelegateView = window.rootViewController?.view,
            let viewContollersView = viewController.view else {
            return
        }
        viewContollersView.frame = (appDelegateWindow?.bounds)!
        appDelegate.window??.addSubview(viewContollersView)
        let transition = CATransition()
        transition.startProgress = 0
        transition.endProgress = 1.0
        transition.type = kCATransitionPush
        transition.subtype = kCATransitionFromRight
        transition.duration = 0.35
        appDelegateView.layer.add(transition, forKey: "transition")
        viewContollersView.layer.add(transition, forKey: "transition")
        appDelegateView.isHidden = true
        viewContollersView.isHidden = false
        appDelegateWindow?.rootViewController = viewController

这篇关于使用Push Transition效果更改RootViewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 21:06