一个易于实现的定制过渡。
这个库将帮助您轻松定制过渡(模态和推送),以便您可以将视图从一个移动到另一个。
克隆或下载此仓库,将 Source
文件夹中的文件添加到您的项目中。
在此方法中,您将非常容易地使用简单的方法设置 EasyTrans,并将其用于推送过渡和模态演示。
func next() {
guard let destinationViewController = storyboard?.instantiateViewControllerWithIdentifier("secondVC") else {
return
}
// This method adds easy trans to the SecondViewController using the provided options for present and dismiss.
setupEasyTransition(on: destinationViewController, presentOptions: TransEasyPresentOptions(duration: 0.4, sourceView: qrButton, blurStyle: UIBlurEffectStyle.Dark), dismissOptions: TransEasyDismissOptions(duration: 0.4, destinationView: qrButton, interactive: true))
if modal {
presentViewController(destinationViewController, animated: true, completion: nil)
} else {
performSegueWithIdentifier(toSecondViewSegueID, sender: sender)
}
}
在目标视图控制器中
extension SecondViewController: TransEasyDestinationViewControllerProtocol {
func transEasyDestinationView() -> UIView {
return qrImage
}
}
并且为了能够在源视图控制器中使用 TransEasy 进行弹出过渡
func transEasyDestinationView() -> UIView {
return qrButton
}
或者,您可以自己实现 transitioningDelegate
并仅使用动画控制器。
let presentAnimator: EasyPresentAnimationController = EasyPresentAnimationController()
let dismissAnimator: EasyDismissAnimationController = EasyDismissAnimationController()
prepareForSegue
中设置 transitioningDelegate
segue.destinationViewController.transitioningDelegate = self
扩展您的视图控制器以使用 TransEasy 过渡
extension ViewController: UIViewControllerTransitioningDelegate {
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
guard let secondVC = presented as? SecondViewController else {
return nil
}
presentAnimator.duration = 0.4
presentAnimator.originalView = qrButton
presentAnimator.destinationView = secondVC.qrImage
presentAnimator.blurEffectStyle = .Dark
return presentAnimator
}
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
guard let secondVC = dismissed as? SecondViewController else {
return nil
}
dismissAnimator.duration = 0.4
dismissAnimator.originalView = secondVC.qrImage
dismissAnimator.destinationView = qrButton
return dismissAnimator
}
}