【发布时间】:2017-08-29 17:36:35
【问题描述】:
我已经在这几个小时了,无法理解我做错了什么。我已经按照我之前的Swift: Problems with custom UIView.transition? 中描述的UITabBarControllerDelegate 装配了自定义标签栏控制器转换
我不使用普通的故事板标签栏按钮,我以编程方式切换 selectedIndex。我的问题是,只有实现了这个:
func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let animator = ModalTransition()
animator.fromView = fromVC.view
animator.toView = toVC.view
return animator
}
索引的动画和切换仅每隔一次发生一次。我有自定义按钮来切换索引,每隔一段时间,当我单击切换按钮时没有任何反应。这是我的动画:
//
// ModalTransition.swift
// Adventures In Design
//
// Created by Skylar Thomas on 8/28/17.
//
import UIKit
class ModalTransition: NSObject, UIViewControllerAnimatedTransitioning {
weak var transitionContext: UIViewControllerContextTransitioning?
var fromView = UIView()
var toView = UIView()
var duration = 1.1
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 1
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
containerView.addSubview(toView)
containerView.sendSubview(toBack: toView)
print("ANIMATING")
UIView.animate(withDuration: duration, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: .curveLinear, animations: {
self.fromView.center.y += 900
}, completion: {
finished in
//only works every OTHER click
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
self.fromView.center.y -= 900
})
}
}
这是什么原因造成的?是什么东西吗
【问题讨论】:
标签: ios swift swift3 uitabbarcontroller transition