1
我一直在這個小時,不能理解我做錯了什麼。我已經按照我之前的Swift: Problems with custom UIView.transition?UIViewControllerAnimatedTransitioning只能在其他時間運行?
所述符合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
})
}
}
這是什麼原因造成的?這是什麼
仍然只適用於所有其他人。你能展示一個動畫例子嗎?也許我沒有正確動畫 – skyguy
當然..檢查編輯答案。讓我知道,如果它有幫助 –
在那裏的東西修復它。謝謝! – skyguy