Search code examples
iosxamarinxamarin.iosgoogle-maps-sdk-ios

ChildViewController/View does not get focus with GMSMapView


Context: I want to achieve something similar with How can I mimic the bottom sheet from the Maps app? based on https://github.com/grendio/XBottomSheet/tree/master/XBottomSheet.Samples/XBottomSheet.Touch

Problem: If I use the BottomSheet with Google Maps for iOS View it does not let me to drag up or down the BottomSheet, even if it adds (it's visible on the screen).

Code: As already mentioned I have a Google Maps View and my BottomSheet View:

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        SetMap();
        SetBottomSheet();
    }

    private void SetMap()
    {
        var frame = new CGRect(0, View.Frame.GetMaxY(), View.Frame.Width, View.Frame.Height);
        mapView = new MapView(View.Frame);
        mapView.MyLocationEnabled = true;

        mapView.BuildingsEnabled = false;
        mapView.SetMinMaxZoom(15f, 18f);

        View = mapView;
    }

    private void SetBottomSheet()
    {
        var bottom = UIScreen.MainScreen.Bounds.Height - UIApplication.SharedApplication.StatusBarFrame.Height;
        bottomSheetViewController = new BottomSheetViewController(100, 300, bottom, true, BottomSheetState.Middle);

        AddChildViewController(bottomSheetViewController);
        View.AddSubview(bottomSheetViewController.View);
        bottomSheetViewController.DidMoveToParentViewController(this);

        bottomSheetViewController.View.Frame = new CGRect(0, View.Frame.GetMaxY(), View.Frame.Width, View.Frame.Height);
    }

How can I wire these two views (mapView and bottomSheetViewController.View) in order to not lose the drag up/down feature from the BottomSheet control?

Even if the question is for Xamarin, an answer from swift or objective-c will do just fine as I will do the 'translation' afterwards.


Solution

  • I had a similar project, my solution at that time was to set the ConsumeGesturesInView property to false.

    So your SetMap() method should look like this:

    private void SetMap()
    {
        var frame = new CGRect(0, View.Frame.GetMaxY(), View.Frame.Width, View.Frame.Height);
        mapView = new MapView(View.Frame);
        mapView.MyLocationEnabled = true;
        mapView.Settings.ConsumeGesturesInView = false;
        mapView.BuildingsEnabled = false;
        mapView.SetMinMaxZoom(15f, 18f);
    
        View = mapView;
    }