问题描述
在我的应用程序中,我有一个@ManyToOne(targetEntity=Item.class,fetch = FetchType.LAZY)
@JoinColumn(name="item_id")
private Item item;
。从那里我MainVC
到另外一个present
,我想在里面ViewControllerB
,所以这是我实现的目标:
push
这正是我想要的工作方式。但是在
let ViewControllerB = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerB") as! ViewControllerB
let navController = UINavigationController(rootViewController: communityVC)
self.present(navController,animated: true,completion: nil)
我也想{}从底部的{em}全屏 ,而不仅仅是ViewControllerB
内部。我叫这个:
push
这是ViewControllerC
中的modalView
,而不是let firstLaunchVC = UIStoryboard(name: "Main",bundle: nil).instantiateViewController(withIdentifier: "FirstLaunchVC")
let transition:CATransition = CATransition()
transition.duration = 0.5
transition.timingFunction = camediatimingFunction(name: camediatimingFunctionName.easeInEaSEOut)
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromTop
self.navigationController?.modalPresentationStyle = .fullScreen
self.navigationController!.view.layer.add(transition,forKey: kCATransition)
self.navigationController?.pushViewController(firstLaunchVC,animated: true)
。我也在终端中收到此消息:
一旦呈现
,设置modalPresentationStyle将不起作用,直到将其关闭并再次呈现。
我希望我能阐明我的问题。让我知道您是否需要有关某事的更多信息。
解决方法
用于过渡的协调器-UINavigationControllerDelegate
创建一个符合UINavigationControllerDelegate
的简单类,我不会详细介绍,但是您问题的答案的主要方法是navigationController(_:animationControllerFor:from:to:)
在此方法的内部,您可以检索正在执行的操作(推,弹出...),此外,您还可以基于视图控制器(从,到)为动画师做出决定。
如果您想要默认动画师,只需返回 nil 。
示例
func navigationController(_ navigationController: UINavigationController,animationControllerFor operation: UINavigationControllerOperation,from fromVC: UIViewController,to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch operation {
case .push: // For push method
return YourCustomAnimator() //Conforming to `UIViewControllerAnimatedTransitioning`
case .pop:
return nil // For pop we want default animation
// I skipped the default case
}
// CASE 2
// Or for example you want to make custom animation only for specific view controller
if toVC is SpecialViewController {
return YourCustomAnimator()
}
return nil // for the rest use default animation
}
,
我通过调用它来解决它:
let navigationController = UINavigationController(rootViewController: firstLaunchVC)
navigationController.modalPresentationStyle = .fullScreen
present(navigationController,animated: true)
即使我不太确定自己是否搞砸了ViewController-Hirarchy
...,它也确实可以按我的方式工作。:D感谢您的帮助