diff options
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | ios/MBXViewController.mm | 141 | ||||
-rw-r--r-- | ios/img/resetPosition.png | bin | 0 -> 7332 bytes | |||
-rw-r--r-- | ios/img/toggleDebug.png | bin | 0 -> 10524 bytes | |||
-rw-r--r-- | ios/img/toggleRaster.png | bin | 0 -> 4966 bytes | |||
-rw-r--r-- | ios/img/unrotate.png | bin | 0 -> 8217 bytes |
6 files changed, 84 insertions, 63 deletions
@@ -130,7 +130,5 @@ This is automatically taken care of as a build phase if you are using the Xcode - Use two fingers to rotate - Double-tap to zoom in one level - Two-finger single-tap to zoom out one level -- Long-press to reset north -- Two-finger long press to reset the transform -- Three-finger long press to toggle debug information -- Four-finger long press to toggle raster +- Single-tap to toggle the command palette visibility for resetting north & the transform, toggling debug, and toggling raster +- Double-tap, long-pressing the second, then pan up and down to "quick zoom" (iPhone only, meant for one-handed use) diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index 7cc616c0e0..3cdab5ffdf 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -29,6 +29,7 @@ NSString *const MBXUpdateActivityNotification = @"MBXUpdateActivityNotification" @property (nonatomic) CGFloat angle; @property (nonatomic) CGFloat quickZoomStart; @property (nonatomic) BOOL debug; +@property (nonatomic) UIView *palette; @end @@ -102,29 +103,20 @@ class MBXMapView rotate.delegate = self; [self.view addGestureRecognizer:rotate]; + UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)]; + singleTap.numberOfTapsRequired = 1; + [self.view addGestureRecognizer:singleTap]; + UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGesture:)]; doubleTap.numberOfTapsRequired = 2; [self.view addGestureRecognizer:doubleTap]; + [singleTap requireGestureRecognizerToFail:doubleTap]; + UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTapGesture:)]; twoFingerTap.numberOfTouchesRequired = 2; [self.view addGestureRecognizer:twoFingerTap]; - UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)]; - [self.view addGestureRecognizer:longPress]; - - UILongPressGestureRecognizer *twoFingerLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerLongPressGesture:)]; - twoFingerLongPress.numberOfTouchesRequired = 2; - [self.view addGestureRecognizer:twoFingerLongPress]; - - UILongPressGestureRecognizer *threeFingerLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleThreeFingerLongPressGesture:)]; - threeFingerLongPress.numberOfTouchesRequired = 3; - [self.view addGestureRecognizer:threeFingerLongPress]; - - UILongPressGestureRecognizer *fourFingerLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleFourFingerLongPressGesture:)]; - fourFingerLongPress.numberOfTouchesRequired = 4; - [self.view addGestureRecognizer:fourFingerLongPress]; - if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { UILongPressGestureRecognizer *quickZoom = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleQuickZoomGesture:)]; @@ -142,6 +134,76 @@ class MBXMapView displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render:)]; [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; + + NSArray *selectorNames = @[ @"unrotate", @"resetPosition", @"toggleDebug", @"toggleRaster" ]; + CGFloat buttonSize = 40; + CGFloat bufferSize = 20; + CGFloat alpha = 0.75; + CGFloat paletteWidth = buttonSize + (2 * bufferSize); + CGFloat paletteHeight = [selectorNames count] * (buttonSize + bufferSize) + bufferSize; + self.palette = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - paletteWidth, + (self.view.bounds.size.height - paletteHeight) / 2, + paletteWidth, + paletteHeight)]; + self.palette.backgroundColor = [UIColor colorWithWhite:0 alpha:alpha]; + self.palette.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; + self.palette.layer.cornerRadius = bufferSize; + [self.view addSubview:self.palette]; + for (NSString *selectorName in selectorNames) + { + UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; + button.frame = CGRectMake(bufferSize, + ([selectorNames indexOfObject:selectorName] * (buttonSize + bufferSize)) + bufferSize, + buttonSize, + buttonSize); + [button setImage:[UIImage imageNamed:[selectorName stringByAppendingString:@".png"]] forState:UIControlStateNormal]; + [button addTarget:self action:NSSelectorFromString(selectorName) forControlEvents:UIControlEventTouchUpInside]; + [self.palette addSubview:button]; + } +} + +- (void)togglePalette +{ + if (self.palette.alpha < 1) + { + self.palette.userInteractionEnabled = YES; + + [UIView animateWithDuration:0.25 animations:^(void) + { + self.palette.alpha = 1; + }]; + } + else + { + self.palette.userInteractionEnabled = NO; + + [UIView animateWithDuration:0.25 animations:^(void) + { + self.palette.alpha = 0; + }]; + } +} + +- (void)unrotate +{ + mapView->map.resetNorth(); +} + +- (void)resetPosition +{ + mapView->map.resetPosition(); +} + +- (void)toggleDebug +{ + mapView->map.toggleDebug(); + + self.debug = ! self.debug; +} + +- (void)toggleRaster +{ + mapView->map.toggleRaster(); } - (void)dealloc @@ -310,6 +372,11 @@ class MBXMapView [self updateRender]; } +- (void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTap +{ + [self togglePalette]; +} + - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap { mapView->map.cancelAnimations(); @@ -330,50 +397,6 @@ class MBXMapView [self updateRender]; } -- (void)handleLongPressGesture:(UILongPressGestureRecognizer *)longPress -{ - mapView->map.cancelAnimations(); - - if (longPress.state == UIGestureRecognizerStateBegan) - mapView->map.resetNorth(); - - [self updateRender]; -} - -- (void)handleTwoFingerLongPressGesture:(UILongPressGestureRecognizer *)twoFingerLongPress -{ - mapView->map.cancelAnimations(); - - if (twoFingerLongPress.state == UIGestureRecognizerStateBegan) - mapView->map.resetPosition(); - - [self updateRender]; -} - -- (void)handleThreeFingerLongPressGesture:(UILongPressGestureRecognizer *)threeFingerLongPress -{ - mapView->map.cancelAnimations(); - - if (threeFingerLongPress.state == UIGestureRecognizerStateBegan) - { - mapView->map.toggleDebug(); - - self.debug = ! self.debug; - } - - [self updateRender]; -} - -- (void)handleFourFingerLongPressGesture:(UILongPressGestureRecognizer *)fourFingerLongPress -{ - mapView->map.cancelAnimations(); - - if (fourFingerLongPress.state == UIGestureRecognizerStateBegan) - mapView->map.toggleRaster(); - - [self updateRender]; -} - - (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom { mapView->map.cancelAnimations(); diff --git a/ios/img/resetPosition.png b/ios/img/resetPosition.png Binary files differnew file mode 100644 index 0000000000..81269cd4fb --- /dev/null +++ b/ios/img/resetPosition.png diff --git a/ios/img/toggleDebug.png b/ios/img/toggleDebug.png Binary files differnew file mode 100644 index 0000000000..aa5e3042fb --- /dev/null +++ b/ios/img/toggleDebug.png diff --git a/ios/img/toggleRaster.png b/ios/img/toggleRaster.png Binary files differnew file mode 100644 index 0000000000..59a6f330fb --- /dev/null +++ b/ios/img/toggleRaster.png diff --git a/ios/img/unrotate.png b/ios/img/unrotate.png Binary files differnew file mode 100644 index 0000000000..63361e99d8 --- /dev/null +++ b/ios/img/unrotate.png |