Swift:自定义 UIView.transition 的问题? [英] Swift: Problems with custom UIView.transition?
问题描述
好的,我已经浏览了 https://developer.apple.com/视频/播放/wwdc2013/218/ 和 SO 问题类似,试图使用标签栏控制器及其视图控制器进行自定义转换,但在弄清楚此处的主要步骤后,我陷入了困惑.
Ok, I have looked through https://developer.apple.com/videos/play/wwdc2013/218/ and SO questions similarly trying to make custom transitions with a tab bar controller and its viewcontrollers but Im running into confusion after figuring out the main steps here.
我需要知道如何(意味着示例代码真的很有帮助)调用自定义 UIView.transition
或在 UIView 中有一个自定义
.我需要使用它在我的标签栏控制器中的标签之间进行滑动/模态模拟转换.option
.过渡
I need to know how (meaning example code would be really helpful) to call a custom UIView.transition
OR just have a custom option
in UIView.transition
. I need to use this to make a sliding/modal -mimicking transition between tabs in my tab bar controller.
让过渡发生的唯一方法是使用以下函数(这会使它们溶解):
The only way I can get a transition to happen is using the below function (this makes them dissolve):
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if selectedViewController == nil || viewController == selectedViewController {
return false
}
let fromView = selectedViewController!.view
let toView = viewController.view
UIView.transition(from: fromView!, to: toView!, duration: 0.3, options: [.transitionCrossDissolve], completion: nil)
return true
}
并在此处手动调用它,我以编程方式更改标签控制器的 *selectedIndex*
:
And calling it manually here where I programmatically chnage the *selectedIndex*
for my tab controller:
//SWITCHES BUTTON -------------------------------------------
func switchTab(index: Int)
{
//transition
self.tabBarController(self, shouldSelect: (viewControllers?[index])!)
我已经阅读并尝试制作一个自定义类 UIViewControllerAnimatedTransitioning
但不知道这将如何以编程方式适应这里 -
I have read about and tried making a custom class UIViewControllerAnimatedTransitioning
but don't know how this would fit in programmatically here -
我尝试将标签栏控制器和 toView
和 fromView
传递到自定义类中,结果没有发生任何事情/动画.这就是我在这里使用 UIView.transition 的原因.
my attempts passing my tab bar controller and the toView
and fromView
into the custom class result in nothing happening/animating. That is why Ive resorted to UIView.transition here.
如何自定义UIView.transition
?我能在这里做什么?
How can I make a custom UIView.transition
? What can I do here?
推荐答案
你应该符合 UITabBarControllerDelegate并创建一个 customTransition 类并按如下方式传递它:
You should conform to UITabBarControllerDelegate and Create a customTransition class and pass it as follows:
func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let animator = TabAnimationManager()
return animator
}
并且 TabAnimationManager 类应该是 UIPercentDrivenInteractiveTransition 的子类并符合 UIViewControllerAnimatedTransitioning 协议.您可以在该类中添加自定义动画.
And Class TabAnimationManager should be a subclass of UIPercentDrivenInteractiveTransition and conform UIViewControllerAnimatedTransitioning protocol. You can add your custom animations in that class.
这篇关于Swift:自定义 UIView.transition 的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!