I’ve a UIImageView above a MapView.
All actions on display screen ought to go to touchesBegan besides pinch which ought to zoom out and in of the map which is beneath.
I believe the best way to perform that is inside a hittest since this appears to be the one place the place i can both return the UIImageView or the MapView. I cant nevertheless examine which UIGestureRecognizer has been used throughout the hittest, so i cant decide which view must be returned.
class ViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate, UIGestureRecognizerDelegate {
@IBOutlet weak var myMapView: GMSMapView!
myMapView.delegate = self
@objc func handlePinch(_ sender: UIPinchGestureRecognizer? = nil) {
//Do one thing
}
lazy var canvasView: CanvasView = {
var overlayView = CanvasView(body: CGRect(x:0, y: 0, width: self.myMapView.body.width, top: self.myMapView.body.top))
overlayView.isUserInteractionEnabled = true
overlayView.delegate = self
let pinchGesture = UIPinchGestureRecognizer(goal: self, motion: #selector(handlePinch))
pinchGesture.delegate = self
overlayView.addGestureRecognizer(pinchGesture)
return overlayView
}()
class CanvasView: UIImageView {
var lastPoint = CGPoint.zero
override func hitTest(_ level: CGPoint, with occasion: UIEvent?) -> UIView? {
var view = tremendous.hitTest(level, with: occasion)
//if pinch is detected return view else return nil
}
override func touchesBegan(_ touches: Set<UITouch>, with occasion: UIEvent?) {
if let contact = touches.first {
//Do one thing...
}
}
}
}
Am i on the proper path or ought to i method this differently?