mousebird-consulting-inc / WhirlyGlobe

WhirlyGlobe Development
Other
830 stars 255 forks source link

MaplyAnnotation contentView tap not working. #452

Closed jerald-acacus closed 8 years ago

jerald-acacus commented 8 years ago

Also, is there any way to disable the one finger gesture on the globe/map so I can stop it from moving when a user tries to swipe on it?

mousebird commented 8 years ago

That sort of makes sense, with the contentView. I'm guessing the tap was being caught by the annotation library I'm using (SMCalloutView) and it's losing track of that if you replace the contentView.

The solution is probably to just add your own gesture on your own contentview.

As for disabling the gestures, there's no really clean way to do that. If you want to change WhirlyGlobeViewController.mm you could add a panGesture property, much like the doubleTapZoomGesture and twoFingerTapGesture.

For a workaround, you could just dig through the gestures on the main UIView and remove them, then put them back when you're done.

domainxh commented 7 years ago

Hi, I tried doing as you recommended by adding tapGesture to the imageView then setting the contentView to that but it doesn't seem to be working.

private func addAnnotationWithTitle(title: String, subtitle: String, loc:MaplyCoordinate) {
    theViewC?.clearAnnotations()

    let a = MaplyAnnotation()
    a.contentView = imageView
    a.contentView.frame = CGRect(x: 0, y: 0, width: 100, height: 80)

    theViewC?.addAnnotation(a, forPoint: loc, offset: CGPoint(x: 0, y: -15))
}

lazy var imageView: UIImageView = {
    let iv = UIImageView(image: UIImage(named: "testImage"))
    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapped))
    tapGesture.delegate = self
    iv.addGestureRecognizer(tapGesture)
    return iv
}()

Also, please advise how to change the white quote box around the image. img_3406

mousebird commented 7 years ago

We're just using the SMCalloutView. You'll need to poke around in its UIView hierarchy.

domainxh commented 7 years ago

For anyone that's having issues with tapping in contentView, you'll need to add UIGestureRecognizerDelegate to the viewController, add tap gesture recognizer, and then set the imageView.isUserInteractionEnabled = true

domainxh commented 7 years ago

Thanks @mousebird for the tip. This is how I resolved it for anyone having similar issues. After annotation is added ... traverse couple layers deep into the superview then comeback down to its subviews and simply set the alpha value to zero.

    theViewC.addAnnotation(annotation, forPoint: loc, offset: CGPoint(x: 0, y: 0))        
    if let backgroundViews = imageView.superview?.superview?.subviews[0].subviews {
        for view in backgroundViews {
            view.alpha = 0
        }
    }

img_d6a52f01aea2-1

mousebird commented 7 years ago

Makes sense. Thanks for posting the fix!