summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2014-03-27 15:05:55 -0700
committerJustin R. Miller <incanus@codesorcery.net>2014-03-27 15:05:55 -0700
commitf2ff4895b9dbd2130b6823cdb31a420ecb2812eb (patch)
treed5f368c6e21386d53750e0be246643645136fd30
parent9b487f2e00416e04cf568d651781183d71eb6756 (diff)
downloadqtlocation-mapboxgl-f2ff4895b9dbd2130b6823cdb31a420ecb2812eb.tar.gz
clean up cryptic iOS gestures & add command palette for commands
-rw-r--r--README.md6
-rw-r--r--ios/MBXViewController.mm141
-rw-r--r--ios/img/resetPosition.pngbin0 -> 7332 bytes
-rw-r--r--ios/img/toggleDebug.pngbin0 -> 10524 bytes
-rw-r--r--ios/img/toggleRaster.pngbin0 -> 4966 bytes
-rw-r--r--ios/img/unrotate.pngbin0 -> 8217 bytes
6 files changed, 84 insertions, 63 deletions
diff --git a/README.md b/README.md
index c730f949b9..8fdf2800a9 100644
--- a/README.md
+++ b/README.md
@@ -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
new file mode 100644
index 0000000000..81269cd4fb
--- /dev/null
+++ b/ios/img/resetPosition.png
Binary files differ
diff --git a/ios/img/toggleDebug.png b/ios/img/toggleDebug.png
new file mode 100644
index 0000000000..aa5e3042fb
--- /dev/null
+++ b/ios/img/toggleDebug.png
Binary files differ
diff --git a/ios/img/toggleRaster.png b/ios/img/toggleRaster.png
new file mode 100644
index 0000000000..59a6f330fb
--- /dev/null
+++ b/ios/img/toggleRaster.png
Binary files differ
diff --git a/ios/img/unrotate.png b/ios/img/unrotate.png
new file mode 100644
index 0000000000..63361e99d8
--- /dev/null
+++ b/ios/img/unrotate.png
Binary files differ