Skip to content

Commit

Permalink
added flag for when menu is showing and additional delegate methods t…
Browse files Browse the repository at this point in the history
…o notify the developer when the contextual menu presents and dismiss in order to give flexibility to take action when the menu presents/dismisses
  • Loading branch information
hectormatos2011 committed Apr 23, 2014
1 parent b4d50ab commit 5ac530e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Classes/BAMContextualMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef enum HMContextualMenuActivateOption : NSUInteger {

@interface BAMContextualMenu : UIView

@property (nonatomic) BOOL menuIsShowing; //Flag to turn off the ability to activate the popup menu. Defaults to YES but will be NO if menuItems array is nil or empty.
@property (nonatomic) BOOL shouldActivateMenu; //Flag to turn off the ability to activate the popup menu. Defaults to YES but will be NO if menuItems array is nil or empty.
@property (nonatomic) BOOL shouldHighlightOutwards; //Defaults to YES. This flag determines whether or not the menu item will animate outwards on highlight. Or just stay in place.

Expand Down Expand Up @@ -62,6 +63,11 @@ typedef enum HMContextualMenuActivateOption : NSUInteger {
- (UIView *)contextualMenu:(BAMContextualMenu *)contextualMenu viewForMenuItemAtIndex:(NSUInteger)index;

@optional
//You would use this delegate method to pause a game or take action when contextual menu overlays your entire screen. For example, If my iOS game implemented this contextual menu by tapping on a character in motion, I would probably pause the game while it's up to give the user time to make a selection on the menu. This is one such example, feel free to use it in any way you would need it.
- (void)contextualMenuActivated:(BAMContextualMenu *)contextualMenu;
//This method could be used to undo any action taken in contextualMenuActivated:.
- (void)contextualMenuDismissed:(BAMContextualMenu *)contextualMenu;

- (void)contextualMenu:(BAMContextualMenu *)contextualMenu didSelectItemAtIndex:(NSUInteger)index;
- (void)contextualMenu:(BAMContextualMenu *)contextualMenu didHighlightItemAtIndex:(NSUInteger)index;
- (UIView *)contextualMenu:(BAMContextualMenu *)contextualMenu viewForHighlightedMenuItemAtIndex:(NSUInteger)index;
Expand Down
11 changes: 8 additions & 3 deletions Classes/BAMContextualMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ @interface BAMContextualMenu () <UIGestureRecognizerDelegate>
BOOL shouldRelayoutSubviews;
BOOL menuItemIsAnimating;
BOOL shouldSelectMenuItem;
BOOL menuIsShowing;
}

@property (nonatomic, weak) id <BAMContextualMenuDelegate> delegate;
Expand All @@ -105,7 +104,7 @@ - (id)initWithContainingView:(UIView *)containingView activateOption:(BAMContext
self.dataSource = contextualDataSource;
self.shouldHighlightOutwards = YES;

menuIsShowing = NO;
_menuIsShowing = NO;

_menuItemDistancePadding = 30.0f;

Expand Down Expand Up @@ -422,7 +421,7 @@ - (NSUInteger)indexAtPoint:(CGPoint)point
#pragma mark Presentation/Dismissal Method
- (void)showMenuItems:(BOOL)show completion:(void (^)())completion
{
menuIsShowing = show;
_menuIsShowing = show;
//totalCircle in this context means the circle from the starting location of the user's touch to the edge of the biggest menu item
CGFloat totalCircleRectX = startingLocation.x - (circleViewWidthHeight / 2.0) - _menuItemDistancePadding - biggestMenuItemWidthHeight;
CGFloat totalCircleRadius = startingLocation.x - totalCircleRectX;
Expand All @@ -431,6 +430,9 @@ - (void)showMenuItems:(BOOL)show completion:(void (^)())completion
[menuItemRectsInWindowArray removeAllObjects];

if (show) {
if (self.delegate && [self.delegate respondsToSelector:@selector(contextualMenuActivated:)]) {
[self.delegate contextualMenuActivated:self];
}
//Calculate proper angle offset
ZZScreenEdge screenCorner = (startingLocation.x < mainWindow.frame.size.width / 2.0) ? kZZScreenEdgeLeft : kZZScreenEdgeRight;

Expand Down Expand Up @@ -511,6 +513,9 @@ - (void)showMenuItems:(BOOL)show completion:(void (^)())completion
}
}];
} else {
if (self.delegate && [self.delegate respondsToSelector:@selector(contextualMenuDismissed:)]) {
[self.delegate contextualMenuDismissed:self];
}
//Animations for dismissal
[UIView animateKeyframesWithDuration:0.3
delay:0.0
Expand Down

0 comments on commit 5ac530e

Please sign in to comment.