0

UIWindowでRootViewControllerを変更し、新しいルートにクロスディゾルブさせるにはどうすればよいですか?

4

2 に答える 2

4

transitionFromViewのメソッドを使用することをお勧めしますUIView。たとえば、次のコードを使用して、移行を処理できます。

- (void)transitionToViewController:(UIViewController *)viewController
                    withTransition:(UIViewAnimationOptions)transition
{
    [UIView transitionFromView:self.window.rootViewController.view
                        toView:viewController.view
                      duration:0.65f
                       options: UIViewAnimationOptionTransitionCrossDissolve
                    completion:^(BOOL finished){
                        self.window.rootViewController = viewController;
                    }];
}

このメソッドのrefdocはここにあります

于 2012-09-23T22:01:47.393 に答える
0

rootviewcontrollerを切り替える方法を知るために私の例を見てみましょう。

 - (void)showTutorialsScreen:(BOOL)animated
{
   NUDTutorialsViewController *tutorialsVC = [[NUDTutorialsViewController alloc] initWithNibName:NSStringFromClass([NUDTutorialsViewController class]) bundle:nil];
   UINavigationController *tutorialsNavController = [[UINavigationController alloc] initWithRootViewController:tutorialsVC];

   [self switchRootViewController:tutorialsNavController animated:animated completion:nil];

}

- (void)showLoadingScreen:(BOOL)animated
{
   NUDLoadingViewController *loadingVC =  [[NUDLoadingViewController alloc]   initWithNibName:NSStringFromClass([NUDLoadingViewController class]) bundle:nil];

   [self switchRootViewController:loadingVC animated:animated completion:nil];

}

- (void)showMainScreen:(BOOL)animated
{
    NUDMainViewController *mainVC = [[NUDMainViewController alloc] initWithNibName:NSStringFromClass([NUDMainViewController class]) bundle:nil];
    UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:mainVC];

    [self switchRootViewController:mainNavController animated:animated completion:nil];

}

 - (void)switchRootViewController:(UIViewController *)aRootViewController animated:(BOOL)animated completion:(void(^)())completion
 {
    if (animated) {
      [UIView transitionWithView:self.window duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        BOOL oldState = [UIView areAnimationsEnabled];
        [UIView setAnimationsEnabled:NO];
        self.window.rootViewController = aRootViewController;
        [UIView setAnimationsEnabled:oldState];
    } completion:^(BOOL finished) {
        if (completion) completion();
    }];
 }
   else {
       self.window.rootViewController = aRootViewController;
        if (completion) completion();
   }
 }
于 2014-06-24T02:24:04.147 に答える