使用 CATransitions 切换视图时出现问题

发布于 2024-10-08 21:10:49 字数 597 浏览 3 评论 0原文

所以我尝试使用此代码在视图之间切换:

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];

但是,该代码不起作用。没有错误,代码执行得很好,但它只是没有做任何事情。我这里有什么问题吗?

So I was attempting to use this code to switch between views:

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];

But, the code doesn't work. There are no errors, and the code executes fine, but it just doesn't do anything. What do I have wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以歌曲疗慰 2024-10-15 21:10:49

您需要将动画添加到父视图的图层,然后将该视图添加为父视图的子视图。

所以

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

你需要使用

[parentView.layer addAnimation:animation forKey:kCATransitionReveal];
[parentView addSubview:theControllerIAmSwitchingTo.view];

You need to add the animation to the layer of parent view, then add the view as a subview of the parent view.

So instead of

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

You need to use

[parentView.layer addAnimation:animation forKey:kCATransitionReveal];
[parentView addSubview:theControllerIAmSwitchingTo.view];
天荒地未老 2024-10-15 21:10:49

就像这样做:

 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];

我注意到问题是您没有在导航堆栈中添加视图,这就是为什么您的视图没有加载并且您看不到动画。

Just do it like:

 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];

I noticed the problem is that you are not adding your view in your navigation stack and that is why your view does not get loaded and you see no animation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文