简体   繁体   English

实现视图控制器之间的平滑自定义转换 swift

[英]Achieving a smooth custom transition between view controllers swift

在此处输入图像描述 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.当在视图 controller 上使用自定义转换查看 controller 时,任何人都可以帮助我修复这个烦人的跳转/故障错误。我不能使用推送,因为我想显示顶部导航栏但隐藏底部标签栏,所以我不得不使用自定义过渡。 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.我想实现一个平滑的过渡,就像在导航 controller 上从视图 controller 到视图 controller 一样。我附上了我的代码。

 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)
    }

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 with CATransition - you can see it slowed down.我认为您看到的不是故障,而是CATransition自动应用的fade - 您可以看到它变慢了。

自定义推送转换 UIViewController

You could go the CABasicAnimation or customizing UIViewControllerTransitions CATransition swift iOS but these will be a lot more work您可以 go CABasicAnimation或自定义UIViewControllerTransitions CATransition swift iOS但这些将需要更多工作

I am not sure why hidesBottomBarWhenPushed does not work for you.我不确定为什么hidesBottomBarWhenPushed对你不起作用。

I have the following view hierarchy:我有以下视图层次结构:

UITabBarController
   - UINavivationController (Tab 1)
     - UIViewController
   - UIViewController2 (Tab 2)

I now do this:我现在这样做:

let dtvc = DetailTransitionVC()
dtvc.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(dtvc, animated: true)

And this seems to give me what you want:这似乎给了我你想要的:

没有标签栏的 UINavigationController 推送删除 iOS Swift

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM