ios - Swift:自定义 UIView.transition 有问题吗?

标签 ios swift swift3 uiview uiviewanimationtransition

好的,我已经查看了https://developer.apple.com/videos/play/wwdc2013/218/和 SO 问题类似地尝试使用选项卡栏 Controller 及其 View Controller 进行自定义转换,但在弄清楚此处的主要步骤后,我遇到了困惑。

我需要知道如何(意味着示例代码非常有帮助)调用自定义UIView.transition或者只是在UIView中有一个自定义选项。过渡。我需要使用它在我的选项卡栏 Controller 中的选项卡之间进行滑动/模态模仿转换。

我可以实现转换的唯一方法是使用以下函数(这使它们溶解):

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
        }

并在这里手动调用它,我以编程方式更改我的选项卡 Controller 的 *selectedIndex*:

//SWITCHES BUTTON -------------------------------------------
    func switchTab(index: Int)

    {
        //transition
        self.tabBarController(self, shouldSelect: (viewControllers?[index])!)

我已经阅读并尝试制作自定义类UIViewControllerAnimatedTransitioning,但不知道如何以编程方式适应这里 -

我尝试将标签栏 Controller 以及 toViewfromView 传递到自定义类中,但没有发生任何事情/动画。这就是我在这里求助于 UIView.transition 的原因。

如何制作自定义UIView.transition?我在这里能做什么?

最佳答案

您应该遵守 UITabBarControllerDelegate 创建一个 customTransition 类并按如下方式传递它:

 func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        let animator = TabAnimationManager()
        return    animator

    }

并且 TabAnimationManager 类应该是 UIPercentDrivenInteractiveTransition 的子类并符合 UIViewControllerAnimatedTransitioning 协议(protocol)。您可以在该类中添加自定义动画。

关于ios - Swift:自定义 UIView.transition 有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45929116/

相关文章:

iOS swift UIImageView 在 tableView 单元格中更改图像

ios - bcsymbolmap 不是有效的标识符?

ios - 向 NSManagedObject 类添加函数

ios - didSelectRowAtIndexPath 没有被调用,因为 UI 点击手势 Swift 解决方案?

ios - swift 全局变量在另一个类中保持为空

ios - 在 ViewController 上显示 SVProgressHUD?

ios - Program/ProgramArguments 无效或缺失

ios - 有什么方法可以检测 Xamarin Forms 应用程序中的语音吗?

swift - 获取 NSRunningApplication 的 ProcessInfo

ios - 如何使用 Swift 在 iOS 10 中调用电话?