问题使用CATransitions切换视图

所以我试图使用此代码在视图之间切换:
CATransition *applicationLoadViewIn = [CATransition animation];

    [applicationLoadViewIn setDuration:1];

    [applicationLoadViewIn setType:kCATransitionReveal];

    [applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

    MyViewControllerClass *theControllerIAmSwitchingTo = [[MyViewControllerClass alloc] init];

    [[theControllerIAmSwitchingTo.view layer] addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];
但是,代码不起作用。没有错误,代码执行正常,但它没有做任何事情。这里有什么问题?     
已邀请:
您需要将动画添加到父视图层,然后将视图添加为父视图的子视图。 而不是
[[theControllerIAmSwitchingTo.view layer] addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];
你需要使用
[parentView.layer addAnimation:animation forKey:kCATransitionReveal];
[parentView addSubview:theControllerIAmSwitchingTo.view];
    
就像这样做:
 CATransition *applicationLoadViewIn = [CATransition animation];

    [applicationLoadViewIn setDuration:1];

    [applicationLoadViewIn setType:kCATransitionReveal];

    [applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

    MyViewControllerClass *theControllerIAmSwitchingTo = [[MyViewControllerClass alloc] init];

    [[theControllerIAmSwitchingTo.view layer] addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];

    [self.navigationController pushViewController:theControllerIAmSwitchingTo animated:NO];
我注意到问题是你没有在导航堆栈中添加你的视图,这就是为什么你的视图没有被加载而你看不到动画。     

要回复问题请先登录注册