How to focus tap on a callout and not on the main view? Swift 3

196 views Asked by At

I have this problem: I'm developing an app with a map, clusters and markers for locations. When a marker or a cluster is clicked, a callout will open: 1) In the marker's callout I have a textview in it, but I can't scroll it because if I tap on it, the map on the background will move. 2) The cluster's callout is a CollectionView with several items in it, but I can't scroll it (direction set horizontally) because if I tap on the collectionView the map will move as well.

So, as title says, how to focus the tap on the callouts when they are showed?

Thank you!

1

There are 1 answers

0
AudioBubble On

I guess you are using your own CalloutView class ?

If so, you can implement delegates in order to handle tap or actions on the CalloutView.

Here is a quick implementation example :

Let's imagine you have a favorite button in your CalloutView.

 protocol MyCalloutViewDelegate: class
    {
        func MyCalloutViewDidTouchFavorite(calloutView: MyCalloutView)
    }

    class MyCalloutView: CalloutView
    {
      ...

    func favoriteButtonDidTouch()
        {
            self.delegate?.MyCalloutViewDidTouchFavorite(self)
        }
    }

And in your MapViewController, you can implement it this way :

// MARK: - MyCalloutViewDelegate

    func MyCalloutViewDidTouchFavorite(calloutView: MyCalloutView)
    {
        let viewController: FavoriteViewController = FavoriteViewController()
        self.navigationController?.pushViewController(viewController, animated: true)

    }

In this example, when the user will tap on the favorite button in the CalloutView it will navigate to the FavoriteViewController.

I hope this example will help you to handle the tap gesture on your CollectionView in the CalloutView for your specific action.