使用 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];
但是,该代码不起作用。没有错误,代码执行得很好,但它只是没有做任何事情。我这里有什么问题吗?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将动画添加到父视图的图层,然后将该视图添加为父视图的子视图。
所以
你需要使用
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
You need to use
就像这样做:
我注意到问题是您没有在导航堆栈中添加视图,这就是为什么您的视图没有加载并且您看不到动画。
Just do it like:
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.