为什么我的 CATransitions 不起作用?
我使用以下代码通过 CATransition 在视图之间切换。
CATransition *applicationLoadViewIn = [CATransition animation];
[applicationLoadViewIn setDuration:20];
[applicationLoadViewIn setType:kCATransitionPush];
[applicationLoadViewIn setSubtype:kCATransitionFromTop];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
ViewToSwitchTo *myviewcontroller = [[ViewToSwitchTo alloc] init];
[self.view.layer addAnimation:applicationLoadViewIn forKey:kCATransitionPush];
[self.view addSubview:myviewcontroller.view];
它主要按照我想要的方式运行。它像它应该的那样从顶部推动,但由于某种原因它的行为很奇怪。首先,我要切换到的视图开始像它应该的那样从底部进入,但由于某种原因,我要切换的视图以低不透明度出现在它的顶部,因此您可以看到它们两个。但是,您还会看到传入的视图,在其自身和另一个视图之上向上移动了大约 100 像素,同样具有低不透明度。就在转换的中间点之前,一切正常,您只能看到进入的视图和离开的视图,做它们应该做的事情。但在中间点之后不久,我要切换到的视图出现在其最终目的地,位于我要切换的视图下方,并且我要切换的视图的不透明度已降低。
这是怎么回事?
I am using the following code to switch between views with CATransition.
CATransition *applicationLoadViewIn = [CATransition animation];
[applicationLoadViewIn setDuration:20];
[applicationLoadViewIn setType:kCATransitionPush];
[applicationLoadViewIn setSubtype:kCATransitionFromTop];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
ViewToSwitchTo *myviewcontroller = [[ViewToSwitchTo alloc] init];
[self.view.layer addAnimation:applicationLoadViewIn forKey:kCATransitionPush];
[self.view addSubview:myviewcontroller.view];
It functions mostly how I want it to. It pushes from the top like it should, however it for some reason acts strangely. First, the view I am switching to starts coming in from the bottom like it should, but for some reason, the view that I am switching FROM appears over the top of it with low opacity, so you see both of them. However, you also see the view that is coming in, shifted maybe 100 pixels upwards, on top of itself and the other view, once again with low opacity. Just before the halfway point of the the transition, everything works fine, you only see the view that is coming in and the view going out, doing what they should be doing. But slightly after the halfway point, the view I am switching to appears in its final destination, under the view I am switching from, and the view I am switching from has been reduced in opacity.
What is going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我真的不明白你想要什么,但希望这段代码能够帮助实现,如果没有,那么告诉你更多关于你的 CATransition
I really not understand what you want but hope this code will help to implement ,if not then tell more about you CATransition
你也可以使用这种方式
,但我建议你使用导航控制器代替
仅仅使用
如果你使用这个,将没有背景视图,你将看到当前视图的白屏。但是如果你添加了子视图,那么你需要手动删除子视图。
You can use this way as well
But I suggest you to use Navigation Controller in place of
just use
If you use this, there will be no background view, you will see white screen of the present view. But if you add subview, then you need to manually remove subview.