快速实现视图控制器之间的平滑自定义转换
任何人都可以帮助我修复在视图控制器上使用自定义转换到视图控制器时这个恼人的跳转/故障错误。我无法使用推送,因为我想显示顶部导航栏但隐藏底部选项卡栏,因此我必须使用自定义转换。我想实现平滑的过渡,就像从导航控制器上的视图控制器转到视图控制器一样。我已附上我的代码。
func presentDetail(_ viewControllerToPresent: UIViewController) {
let transition = CATransition()
transition.duration = 0.25
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
self.view.window!.layer.add(transition, forKey: kCATransition)
present(viewControllerToPresent, animated: false)
}
can anyone help me fix this annoying jump/glitch bug when using a custom transition on view controller to view controller. I can't use push because I want to display the top navigation bar but hide the bottom tab bar so I have had to use a custom transition. I want to acheive a smooth transition like when going from view controller to view controller on a navigation controller. I have attached my code.
func presentDetail(_ viewControllerToPresent: UIViewController) {
let transition = CATransition()
transition.duration = 0.25
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
self.view.window!.layer.add(transition, forKey: kCATransition)
present(viewControllerToPresent, animated: false)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这与给出的评论没有太大不同,但只是一些不容易添加到评论中的解释。
我不认为您看到的是一个小故障,而是使用
CATransition
自动应用的fade
- 您可以看到它变慢了。您可以使用
CABasicAnimation
或自定义href="https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/CustomizingtheTransitionAnimations.html" rel="nofollow noreferrer">UIViewControllerTransitions CATransition swift iOS 但这些将是我要做的 不确定为什么
hidesBottomBarWhenPushed
不适合您。我有以下视图层次结构:
我现在这样做:
这似乎给了我你想要的:
This is not so different from the comments given, however just some explanations that were not easy to add in comments.
I don't think what you see is a glitch, but a
fade
that is automatically applied withCATransition
- you can see it slowed down.You could go the
CABasicAnimation
or customizing UIViewControllerTransitions CATransition swift iOS but these will be a lot more workI am not sure why
hidesBottomBarWhenPushed
does not work for you.I have the following view hierarchy:
I now do this:
And this seems to give me what you want:
我也刚刚经历过这种行为。罪魁祸首在于我的转变方式。我正在推动使用此功能的 VC,因为我也想支持淡入淡出过渡。以前,我使用
.push
作为 AnimationType 来应用过渡。这导致了您在 GIF 中看到的奇怪效果。现在,我将动画设置为可选,只有在未定义的情况下才会 applyTransition。否则,它将使用默认的内置过渡,这是平滑的。这是 applyTransition:
I was just experiencing this behavior as well. The culprit lied in how I was transitioning. I was pushing a VC using this function because I also wanted to support fade transitions. Previously, I was using
.push
as the AnimationType to apply the transition. This was causing that weird effect you see in the GIF. Instead now, I made animation an optional which only will applyTransition if it is not undefined. Otherwise, it will use the default built in transition which is smooth.Here is applyTransition: