2

试图复制 Apple Maps 功能,并带有底部覆盖层。

我已经能够创建自定义 UIPresentationController 并让底部工作表出现,但现在底部工作表似乎阻止了父/呈现视图控制器的所有手势。

这是一个模拟屏幕截图:

在此处输入图像描述

地图注释、菜单按钮(右上角)和地图本身不响应手势、轻按平移或其他方式。搜索栏和分段控制选项卡工作正常。

这是我的 UIPresentationController 和委托:

class MapDrawerPresentationManager: NSObject {

}

extension MapDrawerPresentationManager: UIViewControllerTransitioningDelegate {
    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
    let presentationController = MapDrawerPresentationController(presentedViewController: presented, presenting: presenting)
    return presentationController
    }

}

class MapDrawerPresentationController: UIPresentationController {

    var topGap: CGFloat = 88

    override init(presentedViewController: UIViewController,
     presenting presentingViewController: UIViewController?) {

      super.init(presentedViewController: presentedViewController,
             presenting: presentingViewController)
    }

    override public var frameOfPresentedViewInContainerView: CGRect {
     return CGRect(
         origin: CGPoint(x: 0, y: self.containerView!.frame.height/2),
         size: CGSize(width: self.containerView!.frame.width, // width of parent
                  height: self.containerView!.frame.height-self.topGap))
     }

    override public func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        guard let presentedView = self.presentedView else { return }
    
        presentedView.layer.masksToBounds = true
    }

    override public func containerViewDidLayoutSubviews() {
        super.containerViewDidLayoutSubviews()
        guard let presenterView = self.containerView else { return }
        guard let presentedView = self.presentedView else { return }
    
   
        presentedView.frame = self.frameOfPresentedViewInContainerView
        presentedView.frame.origin.x = (presenterView.frame.width - presentedView.frame.width)
        presentedView.center = CGPoint(x: presentedView.center.x, y: presenterView.center.y * 2)
    
    }

以及我如何呈现/初始化协调员的观点

lazy var presentationDelegate = MapDrawerPresentationManager()

func start() {

    let mapViewController = MapViewController(nibName: nil, bundle: nil)
    
    let drawerVC = MapPanModalViewController(nibName: nil, bundle: nil)
    drawerVC.transitioningDelegate = mapViewController.presentationDelegate
    drawerVC.modalPresentationStyle = .custom

    presenter.pushViewController(mapViewController, animated: false)
    presenter.present(drawerVC, animated: false)
}

我已经尝试从 UIGestureRecognizerDelegate 的“shouldRecognizeSimultaneouslyWith”中返回 true ......但我不知道如何访问 MapView 和 UIButton 的内置手势以设置委托。

如何让 mapKit 和我的菜单按钮的手势/点击工作?

谢谢,

4

0 回答 0