From 10c6f1fe4f530af5c2032ebfce19c4fe29d39642 Mon Sep 17 00:00:00 2001 From: David Chiles Date: Tue, 7 Mar 2017 14:14:56 -0800 Subject: [PATCH] [ios] Match gesture recognizer with map view user interaction state --- platform/ios/CHANGELOG.md | 1 + .../ios/app/MBXEmbeddedMapViewController.h | 5 + .../ios/app/MBXEmbeddedMapViewController.m | 89 +++++++++ platform/ios/app/MBXViewController.m | 10 + platform/ios/app/Main.storyboard | 174 +++++++++++++++++- platform/ios/ios.xcodeproj/project.pbxproj | 6 + platform/ios/src/MGLMapView.mm | 51 +++-- 7 files changed, 315 insertions(+), 21 deletions(-) create mode 100644 platform/ios/app/MBXEmbeddedMapViewController.h create mode 100644 platform/ios/app/MBXEmbeddedMapViewController.m diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index e75f90dd5..53df1f7f4 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ## master * The error passed into `-[MGLMapViewDelegate mapViewDidFailLoadingMap:withError:]` now includes a more specific description and failure reason. ([#8418](https://github.com/mapbox/mapbox-gl-native/pull/8418)) +* Fixed an issue where gesture recognizers associated with map view interactivity were not disabled when their related interactions were disabled. ([#8304](https://github.com/mapbox/mapbox-gl-native/pull/8304)) ## 3.5.0 diff --git a/platform/ios/app/MBXEmbeddedMapViewController.h b/platform/ios/app/MBXEmbeddedMapViewController.h new file mode 100644 index 000000000..976893d49 --- /dev/null +++ b/platform/ios/app/MBXEmbeddedMapViewController.h @@ -0,0 +1,5 @@ +#import + +@interface MBXEmbeddedMapViewController : UIViewController + +@end diff --git a/platform/ios/app/MBXEmbeddedMapViewController.m b/platform/ios/app/MBXEmbeddedMapViewController.m new file mode 100644 index 000000000..f26a007c1 --- /dev/null +++ b/platform/ios/app/MBXEmbeddedMapViewController.m @@ -0,0 +1,89 @@ +#import "MBXEmbeddedMapViewController.h" +#import + +typedef NS_ENUM(NSInteger, MBXEmbeddedControl) { + MBXEmbeddedControlZoom = 0, + MBXEmbeddedControlScroll, + MBXEmbeddedControlRotation, + MBXEmbeddedControlPitch +}; + +@interface MBXEmbeddedMapViewController () + +@property (weak, nonatomic) IBOutlet UIScrollView *scrollView; +@property (weak, nonatomic) IBOutlet MGLMapView *mapView; + +@end + +@implementation MBXEmbeddedMapViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.scrollView.delegate = self; + self.scrollView.contentSize = self.view.bounds.size; +} + +- (IBAction)didSwitch:(UISwitch *)controlSwitch { + [self switchControl:controlSwitch.tag]; +} + +- (IBAction)rotation:(UIRotationGestureRecognizer *)rotationGesture { + self.mapView.transform = CGAffineTransformRotate(rotationGesture.view.transform, rotationGesture.rotation); +} + +- (void)switchControl:(MBXEmbeddedControl) control { + switch (control) { + case MBXEmbeddedControlZoom: + self.mapView.zoomEnabled = !self.mapView.zoomEnabled; + break; + case MBXEmbeddedControlScroll: + self.mapView.scrollEnabled = !self.mapView.scrollEnabled; + break; + case MBXEmbeddedControlRotation: + self.mapView.rotateEnabled = !self.mapView.rotateEnabled; + break; + case MBXEmbeddedControlPitch: + self.mapView.pitchEnabled = !self.mapView.pitchEnabled; + break; + } +} + +- (BOOL)statusForControl:(MBXEmbeddedControl) control { + switch (control) { + case MBXEmbeddedControlZoom: + return self.mapView.zoomEnabled; + case MBXEmbeddedControlScroll: + return self.mapView.scrollEnabled; + case MBXEmbeddedControlRotation: + return self.mapView.rotateEnabled; + case MBXEmbeddedControlPitch: + return self.mapView.pitchEnabled; + } +} + +#pragma mark UIScrollViewDelegate methods + +- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { + return self.mapView; +} + +#pragma mark Class method + ++ (NSString *)titleForControl:(MBXEmbeddedControl) control { + switch (control) { + case MBXEmbeddedControlZoom: + return @"Zoom Enabled"; + case MBXEmbeddedControlScroll: + return @"Scroll Enabled"; + break; + case MBXEmbeddedControlRotation: + return @"Rotation Enabled"; + break; + case MBXEmbeddedControlPitch: + return @"Pitch Enabled"; + break; + } +} + +@end diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 39458c4f3..c249949c0 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -5,6 +5,7 @@ #import "MBXOfflinePacksTableViewController.h" #import "MBXAnnotationView.h" #import "MBXUserLocationAnnotationView.h" +#import "MBXEmbeddedMapViewController.h" #import @@ -79,6 +80,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MBXSettingsMiscellaneousWorldTour, MBXSettingsMiscellaneousCustomUserDot, MBXSettingsMiscellaneousShowZoomLevel, + MBXSettingsMiscellaneousScrollView, MBXSettingsMiscellaneousPrintLogFile, MBXSettingsMiscellaneousDeleteLogFile, }; @@ -350,6 +352,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @"Start World Tour", [NSString stringWithFormat:@"%@ Custom User Dot", (_customUserLocationAnnnotationEnabled ? @"Disable" : @"Enable")], [NSString stringWithFormat:@"%@ Zoom Level", (_showZoomLevelEnabled ? @"Hide" :@"Show")], + @"Embedded Map View", ]]; if (self.debugLoggingEnabled) @@ -615,6 +618,13 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { self.reuseQueueStatsEnabled = NO; break; } + case MBXSettingsMiscellaneousScrollView: + { + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; + MBXEmbeddedMapViewController *embeddedMapViewController = (MBXEmbeddedMapViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MBXEmbeddedMapViewController"]; + [self.navigationController pushViewController:embeddedMapViewController animated:YES]; + break; + } default: NSAssert(NO, @"All miscellaneous setting rows should be implemented"); break; diff --git a/platform/ios/app/Main.storyboard b/platform/ios/app/Main.storyboard index 5819f17ed..40198146a 100644 --- a/platform/ios/app/Main.storyboard +++ b/platform/ios/app/Main.storyboard @@ -1,9 +1,13 @@ - + + + + - + + @@ -21,6 +25,7 @@ + @@ -29,6 +34,7 @@