通过将modalPresentationStyle 设置为.currentContext,我能够“呈现”一个新的视图控制器,另一个,UNDER标签栏。
let newViewController = UIViewController()
newViewController.view.backgroundColor = UIColor.red
newViewController.modalPresentationStyle = .currentContext
newViewController.modalTransitionStyle = UIModalTransitionStyle.flipHorizontal
present(newViewController, animated: true, completion: nil)
编辑:从更多的测试来看,如果有人在出现newViewController 时更改了选项卡,上面可能会有一些错误的行为。
为了“修复”,我创建了一个“切换器”——UIViewController,它在我想在标签栏下翻转的视图控制器之间进行动画处理:
view.addSubview(nextView)
UIView.transition(from: currentView,
to: nextView,
duration: 0.5,
options: animation,
completion: { (_) in
currentView.removeFromSuperview()
})
在这种情况下,currentView 是 ViewControllerOne 的视图(当前可见的),nextView 是 ViewControllerTwo 的视图(我们要呈现的那个)。