在UIViewController外观中添加淡入淡出的动画

Yos*_*far 0 animation objective-c uiviewcontroller ios

当我UIViewController使用此方法更改时,它只显示没有任何动画.我想在视图中添加淡入淡出的动画,我该怎么做?

- (void)changeToRootViewController:(UIViewController*)viewController forNavigationController:(UINavigationController*)naviController class:(Class)class
{
    if ([[naviController.viewControllers lastObject] isKindOfClass:[class class]])
    {
        NSLog(@"Already inside %@.", NSStringFromClass(class));
        return;
    }

    [naviController popToRootViewControllerAnimated:NO];
    NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithArray:naviController.viewControllers];
    [viewControllers removeObjectAtIndex:0];
    naviController.viewControllers = viewControllers;
    [naviController pushViewController:viewController animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

Utt*_*nha 7

你可以尝试这样的事情:

CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromTop;

[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:yourViewController animated:NO];
Run Code Online (Sandbox Code Playgroud)