我正在尝试使用cocoapod,当从导航堆栈弹出视图控制器时添加缩放转换:Zoom Transitioning。当它只是一个与视图控制器一起使用的导航控制器时,这个pod很有用。我遇到的这个问题是我有一个连接到导航控制器的标签栏控制器。该导航控制器在顶部有一个分段控件,用于确定将显示哪个视图,所有视图都是容器视图:
为了让您了解主视图控制器的设置方式(缩写):
//MARK: - View - Child Views are all container views, this determines which view will be displayed based on what is selected by the segmentedController
private func setupView() {
setupSegmentedController()
updateView()
}
private func updateView() {
//The Master VC keeps a reference to all the child VCs, each child vc is only instantiated once and never lose their state even when they are not visible
//Deciding which view to show based on enum value
if segmentedController.selectedSegmentIndex == Selection.genres.rawValue {
//Remove Unselected View Controllers
remove(asChildViewController: viewControllers[.inTheatres])
remove(asChildViewController: viewControllers[.upcoming])
//Create Selected View Controller
viewControllers[.genres] = viewControllers[.genres] ??
createMoviesGenresViewController()
//Add Selected View Controller
add(asChildViewController :viewControllers[.genres])
}
}
//MARK: Actions
func selectionDidChange(_ sender: UISegmentedControl) {
updateView()
}
// MARK: - Create Child View Controllers Programmatically - Activated when Segmented Controller pressed
private func createMoviesUpcomingViewController() -> MoviesUpcomingViewController {
// Load Storyboard
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
// Instantiate View Controller
let viewController = storyboard.instantiateViewController(withIdentifier: "MoviesUpcomingViewController") as! MoviesUpcomingViewController
// Add View Controller as Child View Controller
self.add(asChildViewController: viewController)
return viewController
}
正如您在图片中看到的那样,我将第二个导航控制器设置为自定义控制器(MoviesNavigationController)。
final class MoviesNavigationController: UINavigationController {
private let zoomNavigationControllerDelegate = ZoomNavigationControllerDelegate()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
delegate = zoomNavigationControllerDelegate
}
}
当我将此控制器设置为初始控制器时,pod可以正常工作。但是当我将标签栏控制器设置为像pic中的初始控制器一样,“MoviesUpcomingViewController”中有一个从不调用的委托。
//Zoom
fileprivate var selectedImageView: UIImageView?
extension MoviesUpcomingViewController: ZoomTransitionSourceDelegate {
func transitionSourceImageView() -> UIImageView {
return selectedImageView ?? UIImageView()
}
func transitionSourceImageViewFrame(forward: Bool) -> CGRect {
guard let selectedImageView = selectedImageView else { return CGRect.zero }
return selectedImageView.convert(selectedImageView.bounds, to: view)
}
func transitionSourceWillBegin() {
selectedImageView?.isHidden = true
}
func transitionSourceDidEnd() {
selectedImageView?.isHidden = false
}
func transitionSourceDidCancel() {
selectedImageView?.isHidden = false
}
}
有没有人知道如何使用当前设置正常工作?