From 19cf4cdc46937d22f2f61f4b2a3ae1f483a3d23f Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Thu, 25 Jun 2015 16:24:07 +0300 Subject: [PATCH] [ios] Added double tap handling to menu button. --- .../SideMenu/MWMSideMenuButton.h | 5 ++-- .../SideMenu/MWMSideMenuButton.mm | 26 +++++++++++++++++++ .../SideMenu/MWMSideMenuButtonDelegate.h | 14 ++++++++++ .../SideMenu/MWMSideMenuManager.mm | 15 +++++++++-- .../SideMenu/MWMSideMenuViews.xib | 7 ++--- iphone/Maps/Maps.xcodeproj/project.pbxproj | 2 ++ 6 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButtonDelegate.h diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.h b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.h index 0b293c20c9..89f33cfd09 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.h +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.h @@ -6,12 +6,13 @@ // Copyright (c) 2015 MapsWithMe. All rights reserved. // -#import +#import "MWMSideMenuButtonDelegate.h" #import "MWMSideMenuDelegate.h" +#import @interface MWMSideMenuButton : UIButton -@property (weak, nonatomic) id delegate; +@property (weak, nonatomic) id delegate; - (instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("initWithFrame is not available"))); - (instancetype)init __attribute__((unavailable("init is not available"))); diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.mm index 46bb9377b6..ebcb42f7cd 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButton.mm @@ -75,6 +75,32 @@ } } +- (void)handleSingleTap +{ + [self.delegate handleSingleTap]; +} + +- (void)handleDoubleTap +{ + [self.delegate handleDoubleTap]; +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + UITouch * touch = [touches anyObject]; + if (touch.tapCount > 1) + [NSObject cancelPreviousPerformRequestsWithTarget:self]; +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event +{ + UITouch * touch = [touches anyObject]; + if (touch.tapCount == 1) + [self performSelector:@selector(handleSingleTap) withObject:nil afterDelay:0.1]; + else + [self handleDoubleTap]; +} + #pragma mark - Properties - (void)setHidden:(BOOL)hidden animated:(BOOL)animated diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButtonDelegate.h b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButtonDelegate.h new file mode 100644 index 0000000000..b91f918ede --- /dev/null +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuButtonDelegate.h @@ -0,0 +1,14 @@ +// +// MWMSideMenuButtonDelegate.h +// Maps +// +// Created by Ilya Grechuhin on 25.06.15. +// Copyright (c) 2015 MapsWithMe. All rights reserved. +// + +@protocol MWMSideMenuTapProtocol + +- (void)handleSingleTap; +- (void)handleDoubleTap; + +@end \ No newline at end of file diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuManager.mm index ee38ec4947..91587fc877 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuManager.mm @@ -15,6 +15,7 @@ #import "MWMMapViewControlsCommon.h" #import "MWMMapViewControlsManager.h" #import "MWMSideMenuButton.h" +#import "MWMSideMenuButtonDelegate.h" #import "MWMSideMenuDelegate.h" #import "MWMSideMenuManager.h" #import "MWMSideMenuView.h" @@ -29,7 +30,7 @@ static NSString * const kMWMSideMenuViewsNibName = @"MWMSideMenuViews"; extern NSString * const kAlohalyticsTapEventKey; -@interface MWMSideMenuManager() +@interface MWMSideMenuManager() @property (weak, nonatomic) MapViewController * controller; @property (nonatomic) IBOutlet MWMSideMenuButton * menuButton; @@ -114,7 +115,7 @@ extern NSString * const kAlohalyticsTapEventKey; [self.controller.searchView setState:SearchViewStateFullscreen animated:YES]; } -- (IBAction)toggleMenu +- (void)toggleMenu { if (self.state == MWMSideMenuStateActive) self.state = MWMSideMenuStateInactive; @@ -122,6 +123,16 @@ extern NSString * const kAlohalyticsTapEventKey; self.state = MWMSideMenuStateActive; } +- (void)handleSingleTap +{ + [self toggleMenu]; +} + +- (void)handleDoubleTap +{ + [self menuActionOpenSearch]; +} + #pragma mark - MWMSideMenuInformationDisplayProtocol - (void)setRulerPivot:(m2::PointD)pivot diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuViews.xib b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuViews.xib index c1775da602..7b645a647e 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuViews.xib +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/SideMenu/MWMSideMenuViews.xib @@ -1,8 +1,8 @@ - + - + @@ -213,9 +213,6 @@ - - - diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 9d83a91ce8..b1fb7d0816 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -392,6 +392,7 @@ 34BC721E1B0DECAE0012A34B /* MWMZoomButtonsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMZoomButtonsView.h; sourceTree = ""; }; 34BC721F1B0DECAE0012A34B /* MWMZoomButtonsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWMZoomButtonsView.m; sourceTree = ""; }; 34BC72201B0DECAE0012A34B /* MWMZoomButtonsView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMZoomButtonsView.xib; sourceTree = ""; }; + 34D56DDE1B3C310A00DFF4CC /* MWMSideMenuButtonDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMSideMenuButtonDelegate.h; sourceTree = ""; }; 34DF4D0F1AE77B9F0012702D /* MWMWKInterfaceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMWKInterfaceController.h; sourceTree = ""; }; 34DF4D101AE77B9F0012702D /* MWMWKInterfaceController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMWKInterfaceController.mm; sourceTree = ""; }; 3D443C9C19E421EE0025C2FC /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Localizable.strings; sourceTree = ""; }; @@ -1077,6 +1078,7 @@ 34BC72131B0DECAE0012A34B /* MWMMapViewControlsCommon.h */, 34BC72141B0DECAE0012A34B /* MWMSideMenuButton.h */, 34BC72151B0DECAE0012A34B /* MWMSideMenuButton.mm */, + 34D56DDE1B3C310A00DFF4CC /* MWMSideMenuButtonDelegate.h */, 34BC72161B0DECAE0012A34B /* MWMSideMenuManager.h */, 34BC72171B0DECAE0012A34B /* MWMSideMenuManager.mm */, 34BC72181B0DECAE0012A34B /* MWMSideMenuView.h */,