diff --git a/GHContextMenu/GHCollectionViewController.m b/GHContextMenu/GHCollectionViewController.m index 7230bbc..6e11bc7 100644 --- a/GHContextMenu/GHCollectionViewController.m +++ b/GHContextMenu/GHCollectionViewController.m @@ -29,8 +29,10 @@ - (void)viewDidLoad [super viewDidLoad]; GHContextMenuView* overlay = [[GHContextMenuView alloc] init]; + overlay.menuViewBackgroundColor = [UIColor whiteColor]; overlay.dataSource = self; overlay.delegate = self; + overlay.menuViewBackgroundColor = [UIColor colorWithWhite:1.0f alpha:0.85f]; // Do any additional setup after loading the view. // [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; @@ -89,21 +91,32 @@ -(UIImage*) imageForItemAtIndex:(NSInteger)index NSString* imageName = nil; switch (index) { case 0: - imageName = @"facebook-white"; + imageName = @"gp"; break; case 1: - imageName = @"twitter-white"; + imageName = @"p"; break; case 2: - imageName = @"google-plus-white"; + imageName = @"t"; break; - case 3: - imageName = @"linkedin-white"; + default: + break; + } + return [UIImage imageNamed:imageName]; +} + +- (UIImage *)highlightImageForItemAtIndex:(NSInteger)index { + NSString* imageName = nil; + switch (index) { + case 0: + imageName = @"gps"; + break; + case 1: + imageName = @"ps"; break; - case 4: - imageName = @"pinterest-white"; + case 2: + imageName = @"ts"; break; - default: break; } @@ -117,21 +130,14 @@ - (void) didSelectItemAtIndex:(NSInteger)selectedIndex forMenuAtPoint:(CGPoint)p NSString* msg = nil; switch (selectedIndex) { case 0: - msg = @"Facebook Selected"; + msg = @"Google+ Selected"; break; case 1: - msg = @"Twitter Selected"; + msg = @"Pinterest Selected"; break; case 2: - msg = @"Google Plus Selected"; - break; - case 3: - msg = @"Linkedin Selected"; - break; - case 4: - msg = @"Pinterest Selected"; + msg = @"Twitter Selected"; break; - default: break; } @@ -143,5 +149,34 @@ - (void) didSelectItemAtIndex:(NSInteger)selectedIndex forMenuAtPoint:(CGPoint)p } +- (NSString *)tipForItemAtIndex:(NSInteger)index { + NSString* tip = @""; + switch (index) { + case 0: + tip = @"Google+"; + break; + case 1: + tip = @"Pinterest"; + break; + case 2: + tip = @"Twitter"; + break; + default: + break; + } + return tip; +} + +- (UIView *)overlayViewAtPoint:(CGPoint)point { + NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:point]; + UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; + CGPoint origin = cell.frame.origin; + origin = [self.view convertPoint:origin fromView:self.collectionView]; + UIView *snap = [cell snapshotViewAfterScreenUpdates:NO]; + CGRect snapFrame = cell.bounds; + snapFrame.origin = origin; + snap.frame = snapFrame; + return snap; +} @end diff --git a/GHContextMenu/GHContextMenuView.h b/GHContextMenu/GHContextMenuView.h index 51975b6..a5b2fd5 100644 --- a/GHContextMenu/GHContextMenuView.h +++ b/GHContextMenu/GHContextMenuView.h @@ -27,6 +27,10 @@ typedef NS_ENUM(NSInteger, GHContextMenuActionType){ - (void) longPressDetected:(UIGestureRecognizer*) gestureRecognizer; +@property (nonatomic, strong) UIFont *tipFont; +@property (nonatomic, strong) UIColor *tipColor; +@property (nonatomic, strong) UIColor *menuViewBackgroundColor; + @end @protocol GHContextOverlayViewDataSource @@ -37,6 +41,9 @@ typedef NS_ENUM(NSInteger, GHContextMenuActionType){ @optional -(BOOL) shouldShowMenuAtPoint:(CGPoint) point; +- (UIImage*) highlightImageForItemAtIndex:(NSInteger) index; +- (NSString*) tipForItemAtIndex:(NSInteger) index; +- (UIView *) overlayViewAtPoint:(CGPoint) point; @end diff --git a/GHContextMenu/GHContextMenuView.m b/GHContextMenu/GHContextMenuView.m index bf7c93a..41ef620 100644 --- a/GHContextMenu/GHContextMenuView.m +++ b/GHContextMenu/GHContextMenuView.m @@ -52,8 +52,13 @@ @interface GHContextMenuView () @property (nonatomic, strong) NSMutableArray* itemLocations; @property (nonatomic) NSInteger prevIndex; -@property (nonatomic) CGColorRef itemBGHighlightedColor; -@property (nonatomic) CGColorRef itemBGColor; +@property (nonatomic, copy) NSArray *normalImages; +@property (nonatomic, copy) NSArray *highlightImages; +@property (nonatomic, copy) NSArray *tips; + +@property (nonatomic, strong) UILabel *tipLabel; +@property (nonatomic) CGRect tipLabelFrame; +@property (nonatomic, strong) UIView *overlayView; @end @@ -82,9 +87,18 @@ - (id)init _arcAngle = M_PI_2; _radius = 90; - self.itemBGColor = [UIColor grayColor].CGColor; - self.itemBGHighlightedColor = [UIColor redColor].CGColor; - + self.tipLabel = [[UILabel alloc] init]; + if (self.tipFont) { + self.tipLabel.font = self.tipFont; + } else { + self.tipLabel.font = [UIFont boldSystemFontOfSize:36.0f]; + } + if (self.tipColor) { + self.tipLabel.textColor = self.tipColor; + } else { + self.tipLabel.textColor = [UIColor blackColor]; + } + [self addSubview:self.tipLabel]; } return self; } @@ -157,8 +171,16 @@ - (void) longPressDetected:(UIGestureRecognizer*) gestureRecognizer [[UIApplication sharedApplication].keyWindow addSubview:self]; self.longPressLocation = [gestureRecognizer locationInView:self]; + if ([self.dataSource respondsToSelector:@selector(overlayViewAtPoint:)]) { + self.overlayView = [self.dataSource overlayViewAtPoint:pointInView]; + [self insertSubview:self.overlayView atIndex:0]; + } - self.layer.backgroundColor = [UIColor colorWithWhite:0.1f alpha:.8f].CGColor; + UIColor *backgroundColor = [UIColor colorWithWhite:0.1f alpha:.8f]; + if (self.menuViewBackgroundColor) { + backgroundColor = self.menuViewBackgroundColor; + } + self.layer.backgroundColor = self.menuViewBackgroundColor.CGColor; self.isShowing = YES; [self animateMenu:YES]; [self setNeedsDisplay]; @@ -192,27 +214,18 @@ - (void) hideMenu [self animateMenu:NO]; [self setNeedsDisplay]; [self removeFromSuperview]; + [self.overlayView removeFromSuperview]; } } - (CALayer*) layerWithImage:(UIImage*) image { - CALayer *layer = [CALayer layer]; - layer.bounds = CGRectMake(0, 0, GHMenuItemSize, GHMenuItemSize); - layer.cornerRadius = GHMenuItemSize/2; - layer.borderColor = [UIColor whiteColor].CGColor; - layer.borderWidth = GHBorderWidth; - layer.shadowColor = [UIColor blackColor].CGColor; - layer.shadowOffset = CGSizeMake(0, -1); - layer.backgroundColor = self.itemBGColor; - CALayer* imageLayer = [CALayer layer]; imageLayer.contents = (id) image.CGImage; imageLayer.bounds = CGRectMake(0, 0, GHMenuItemSize*2/3, GHMenuItemSize*2/3); imageLayer.position = CGPointMake(GHMenuItemSize/2, GHMenuItemSize/2); - [layer addSublayer:imageLayer]; - return layer; + return imageLayer; } - (void) setDataSource:(id)dataSource @@ -228,15 +241,36 @@ - (void) reloadData { [self.menuItems removeAllObjects]; [self.itemLocations removeAllObjects]; + NSMutableArray *normalImages = @[].mutableCopy; + NSMutableArray *highlightImages = @[].mutableCopy; + NSMutableArray *tips = @[].mutableCopy; if (self.dataSource != nil) { NSInteger count = [self.dataSource numberOfMenuItems]; for (int i = 0; i < count; i++) { UIImage* image = [self.dataSource imageForItemAtIndex:i]; - CALayer *layer = [self layerWithImage:image]; + [normalImages addObject:image]; + if ([self.dataSource respondsToSelector:@selector(highlightImageForItemAtIndex:)]) { + UIImage *highlightImage = [self.dataSource highlightImageForItemAtIndex:i]; + [highlightImages addObject:highlightImage]; + } else { + [highlightImages addObject:image]; + } + if ([self.dataSource respondsToSelector:@selector(tipForItemAtIndex:)]) { + NSString *tip = [self.dataSource tipForItemAtIndex:i]; + [tips addObject:tip]; + } else { + [tips addObject:@""]; + } + CALayer *imageLayer = [self layerWithImage:image]; + CALayer *layer = [CALayer layer]; + [layer addSublayer:imageLayer]; [self.layer addSublayer:layer]; [self.menuItems addObject:layer]; } + self.normalImages = normalImages.copy; + self.highlightImages = highlightImages.copy; + self.tips = tips.copy; } } @@ -267,6 +301,29 @@ - (void) layoutMenuItems layer.transform = CATransform3DRotate(CATransform3DIdentity, angle, 0, 0, 1); } } + + [self layoutTipLabel]; +} + +- (void)layoutTipLabel { + CGFloat dx = self.center.x - self.longPressLocation.x; + CGFloat dy = self.center.y - self.longPressLocation.y; + CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; + CGPoint lableOrigin = CGPointZero; + if (dx >= 0) { + lableOrigin.x = screenWidth / 2.0f + 25.0f; + } else { + lableOrigin.x = 25.0f; + } + if (dy >= 0) { + lableOrigin.y = self.longPressLocation.y + 150.0f - 44.0f; + } else { + lableOrigin.y = self.longPressLocation.y - 150.0f; + } + + CGRect labelFrame = CGRectMake(lableOrigin.x, lableOrigin.y, 300.0f, 44.0f); + self.tipLabelFrame = labelFrame; + self.tipLabel.frame = labelFrame; } - (GHMenuItemLocation*) locationForItemAtIndex:(NSUInteger) index @@ -322,7 +379,7 @@ - (CGFloat) angleBeweenStartinPoint:(CGPoint) startingPoint endingPoint:(CGPoint float bearingRadians = atan2f(originPoint.y, originPoint.x); bearingRadians = (bearingRadians > 0.0 ? bearingRadians : (M_PI*2 + bearingRadians)); - + return bearingRadians; } @@ -351,10 +408,21 @@ - (void) highlightMenuItemForPoint } } + CGFloat tipMove = self.curretnLocation.y - self.longPressLocation.y; + if (tipMove >= self.radius) { + tipMove = self.radius; + } + if (tipMove <= -self.radius) { + tipMove = -self.radius; + } + CGRect tipLabelFrame = self.tipLabelFrame; + tipLabelFrame.origin.y += tipMove / 7.0f; + self.tipLabel.frame = tipLabelFrame; + if (closeToIndex >= 0 && closeToIndex < self.menuItems.count) { GHMenuItemLocation* itemLocation = [self.itemLocations objectAtIndex:closeToIndex]; - + CGFloat distanceFromCenter = sqrt(pow(self.curretnLocation.x - self.longPressLocation.x, 2)+ pow(self.curretnLocation.y-self.longPressLocation.y, 2)); CGFloat toleranceDistance = (self.radius - GHMainItemSize/(2*sqrt(2)) - GHMenuItemSize/(2*sqrt(2)) )/2; @@ -362,8 +430,15 @@ - (void) highlightMenuItemForPoint CGFloat distanceFromItem = fabsf(distanceFromCenter - self.radius) - GHMenuItemSize/(2*sqrt(2)) ; if (fabs(distanceFromItem) < toleranceDistance ) { + [self showTips]; CALayer *layer = [self.menuItems objectAtIndex:closeToIndex]; - layer.backgroundColor = self.itemBGHighlightedColor; + for (CALayer *sublayer in layer.sublayers) { + [sublayer removeFromSuperlayer]; + } + CALayer *imageLayer = [self layerWithImage:self.highlightImages[closeToIndex]]; + [layer addSublayer:imageLayer]; + + self.tipLabel.text = self.tips[closeToIndex]; CGFloat distanceFromItemBorder = fabs(distanceFromItem); @@ -389,21 +464,45 @@ - (void) highlightMenuItemForPoint self.prevIndex = closeToIndex; } else if(self.prevIndex >= 0) { + [self hideTips]; [self resetPreviousSelection]; } }else { + [self hideTips]; [self resetPreviousSelection]; } } } +- (void)showTips { + [self.tipLabel.layer removeAllAnimations]; + [UIView animateWithDuration:0.1f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{ + self.tipLabel.alpha = 1.0f; + } completion:^(BOOL finished) { + + }]; +} + +- (void)hideTips { + [self.tipLabel.layer removeAllAnimations]; + [UIView animateWithDuration:0.1f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{ + self.tipLabel.alpha = 0.0f; + } completion:^(BOOL finished) { + + }]; +} + - (void) resetPreviousSelection { if (self.prevIndex >= 0) { CALayer *layer = self.menuItems[self.prevIndex]; + for (CALayer *sublayer in layer.sublayers) { + [sublayer removeFromSuperlayer]; + } + CALayer *imageLayer = [self layerWithImage:self.normalImages[self.prevIndex]]; + [layer addSublayer:imageLayer]; GHMenuItemLocation* itemLocation = [self.itemLocations objectAtIndex:self.prevIndex]; layer.position = itemLocation.position; - layer.backgroundColor = self.itemBGColor; layer.transform = CATransform3DIdentity; self.prevIndex = -1; } @@ -460,7 +559,6 @@ - (void)animationDidStart:(CAAnimation *)anim [CATransaction begin]; [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; layer.position = toPosition; - layer.backgroundColor = self.itemBGColor; layer.opacity = 0.0f; layer.transform = CATransform3DIdentity; [CATransaction commit]; diff --git a/GHContextMenu/GHViewController.m b/GHContextMenu/GHViewController.m index c6db62c..f1e738b 100644 --- a/GHContextMenu/GHViewController.m +++ b/GHContextMenu/GHViewController.m @@ -25,6 +25,7 @@ - (void)viewDidLoad GHContextMenuView* overlay = [[GHContextMenuView alloc] init]; overlay.dataSource = self; overlay.delegate = self; + overlay.menuViewBackgroundColor = [UIColor colorWithWhite:1.0f alpha:0.85f]; UILongPressGestureRecognizer* _longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:overlay action:@selector(longPressDetected:)]; [self.imageView setUserInteractionEnabled:YES]; @@ -47,21 +48,32 @@ -(UIImage*) imageForItemAtIndex:(NSInteger)index NSString* imageName = nil; switch (index) { case 0: - imageName = @"facebook-white"; + imageName = @"gp"; break; case 1: - imageName = @"twitter-white"; + imageName = @"p"; break; case 2: - imageName = @"google-plus-white"; + imageName = @"t"; break; - case 3: - imageName = @"linkedin-white"; + default: break; - case 4: - imageName = @"pinterest-white"; + } + return [UIImage imageNamed:imageName]; +} + +- (UIImage *)highlightImageForItemAtIndex:(NSInteger)index { + NSString* imageName = nil; + switch (index) { + case 0: + imageName = @"gps"; + break; + case 1: + imageName = @"ps"; + break; + case 2: + imageName = @"ts"; break; - default: break; } @@ -73,21 +85,14 @@ - (void) didSelectItemAtIndex:(NSInteger)selectedIndex forMenuAtPoint:(CGPoint)p NSString* msg = nil; switch (selectedIndex) { case 0: - msg = @"Facebook Selected"; + msg = @"Google+ Selected"; break; case 1: - msg = @"Twitter Selected"; + msg = @"Pinterest Selected"; break; case 2: - msg = @"Google Plus Selected"; - break; - case 3: - msg = @"Linkedin Selected"; - break; - case 4: - msg = @"Pinterest Selected"; + msg = @"Twitter Selected"; break; - default: break; } @@ -97,4 +102,22 @@ - (void) didSelectItemAtIndex:(NSInteger)selectedIndex forMenuAtPoint:(CGPoint)p } +- (NSString *)tipForItemAtIndex:(NSInteger)index { + NSString* tip = @""; + switch (index) { + case 0: + tip = @"Google+"; + break; + case 1: + tip = @"Pinterest"; + break; + case 2: + tip = @"Twitter"; + break; + default: + break; + } + return tip; +} + @end diff --git a/GHContextMenu/Images.xcassets/AppIcon.appiconset/Contents.json b/GHContextMenu/Images.xcassets/AppIcon.appiconset/Contents.json index a396706..b8236c6 100644 --- a/GHContextMenu/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/GHContextMenu/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,19 +1,44 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "40x40", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "60x60", "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" } ], "info" : { diff --git a/GHContextMenu/Images.xcassets/Contents.json b/GHContextMenu/Images.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/GHContextMenu/Images.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GHContextMenu/Images.xcassets/gp.imageset/Contents.json b/GHContextMenu/Images.xcassets/gp.imageset/Contents.json new file mode 100644 index 0000000..5623b1f --- /dev/null +++ b/GHContextMenu/Images.xcassets/gp.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "gp.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GHContextMenu/Images.xcassets/gp.imageset/gp.png b/GHContextMenu/Images.xcassets/gp.imageset/gp.png new file mode 100644 index 0000000..ef1a82d Binary files /dev/null and b/GHContextMenu/Images.xcassets/gp.imageset/gp.png differ diff --git a/GHContextMenu/Images.xcassets/gps.imageset/Contents.json b/GHContextMenu/Images.xcassets/gps.imageset/Contents.json new file mode 100644 index 0000000..adf307b --- /dev/null +++ b/GHContextMenu/Images.xcassets/gps.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "gps.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GHContextMenu/Images.xcassets/gps.imageset/gps.png b/GHContextMenu/Images.xcassets/gps.imageset/gps.png new file mode 100644 index 0000000..c4bc83d Binary files /dev/null and b/GHContextMenu/Images.xcassets/gps.imageset/gps.png differ diff --git a/GHContextMenu/Images.xcassets/p.imageset/Contents.json b/GHContextMenu/Images.xcassets/p.imageset/Contents.json new file mode 100644 index 0000000..5e6411d --- /dev/null +++ b/GHContextMenu/Images.xcassets/p.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "p.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GHContextMenu/Images.xcassets/p.imageset/p.png b/GHContextMenu/Images.xcassets/p.imageset/p.png new file mode 100644 index 0000000..16572d5 Binary files /dev/null and b/GHContextMenu/Images.xcassets/p.imageset/p.png differ diff --git a/GHContextMenu/Images.xcassets/ps.imageset/Contents.json b/GHContextMenu/Images.xcassets/ps.imageset/Contents.json new file mode 100644 index 0000000..e9fcfd9 --- /dev/null +++ b/GHContextMenu/Images.xcassets/ps.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "ps.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GHContextMenu/Images.xcassets/ps.imageset/ps.png b/GHContextMenu/Images.xcassets/ps.imageset/ps.png new file mode 100644 index 0000000..2567e65 Binary files /dev/null and b/GHContextMenu/Images.xcassets/ps.imageset/ps.png differ diff --git a/GHContextMenu/Images.xcassets/t.imageset/Contents.json b/GHContextMenu/Images.xcassets/t.imageset/Contents.json new file mode 100644 index 0000000..a570da6 --- /dev/null +++ b/GHContextMenu/Images.xcassets/t.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "t.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GHContextMenu/Images.xcassets/t.imageset/t.png b/GHContextMenu/Images.xcassets/t.imageset/t.png new file mode 100644 index 0000000..de0ebc1 Binary files /dev/null and b/GHContextMenu/Images.xcassets/t.imageset/t.png differ diff --git a/GHContextMenu/Images.xcassets/ts.imageset/Contents.json b/GHContextMenu/Images.xcassets/ts.imageset/Contents.json new file mode 100644 index 0000000..8300d11 --- /dev/null +++ b/GHContextMenu/Images.xcassets/ts.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "ts.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/GHContextMenu/Images.xcassets/ts.imageset/ts.png b/GHContextMenu/Images.xcassets/ts.imageset/ts.png new file mode 100644 index 0000000..4ab4a00 Binary files /dev/null and b/GHContextMenu/Images.xcassets/ts.imageset/ts.png differ diff --git a/GHContextMenuDemo.xcodeproj/project.pbxproj b/GHContextMenuDemo.xcodeproj/project.pbxproj index f2aef90..3b4d416 100644 --- a/GHContextMenuDemo.xcodeproj/project.pbxproj +++ b/GHContextMenuDemo.xcodeproj/project.pbxproj @@ -259,6 +259,9 @@ LastUpgradeCheck = 0500; ORGANIZATIONNAME = Tapasya; TargetAttributes = { + 84F0C30218962C3F00870008 = { + DevelopmentTeam = 7H6KWF2CU7; + }; 84F0C32318962C3F00870008 = { TestTargetID = 84F0C30218962C3F00870008; }; @@ -451,6 +454,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + DEVELOPMENT_TEAM = 7H6KWF2CU7; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "GHContextMenu/GHContextMenu-Prefix.pch"; INFOPLIST_FILE = "GHContextMenu/GHContextMenu-Info.plist"; @@ -464,6 +468,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + DEVELOPMENT_TEAM = 7H6KWF2CU7; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "GHContextMenu/GHContextMenu-Prefix.pch"; INFOPLIST_FILE = "GHContextMenu/GHContextMenu-Info.plist"; diff --git a/README.md b/README.md index 6ef172f..e5b453e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ #GHContextMenu - Pinterest like context menu control for iOS -![alt tag](https://github.com/GnosisHub/GHContextMenu/blob/master/cmocv.gif) -![alt tag](https://github.com/GnosisHub/GHContextMenu/blob/master/cmocv5.gif) -![alt tag](https://github.com/GnosisHub/GHContextMenu/blob/master/cmov.gif) +![alt tag](https://github.com/noark9/GHContextMenu/blob/master/cmocv.gif) +![alt tag](https://github.com/noark9/GHContextMenu/blob/master/cmocv5.gif) +![alt tag](https://github.com/noark9/GHContextMenu/blob/master/cmov.gif) This is user friendly solution for showing context menu upon long press. It is inspired from the Pinterest iOS app @@ -17,15 +17,26 @@ Sample app contains examples of how to add context menu for UIView and UICollect ### Sample Code ```objc -// Creating +// create menu overlay GHContextMenuView* overlay = [[GHContextMenuView alloc] init]; + overlay.menuViewBackgroundColor = [UIColor whiteColor]; overlay.dataSource = self; overlay.delegate = self; - + overlay.menuViewBackgroundColor = [UIColor colorWithWhite:1.0f alpha:0.85f]; + UILongPressGestureRecognizer* _longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:overlay action:@selector(longPressDetected:)]; - [self.view addGestureRecognizer:_longPressRecognizer]; + [self.collectionView addGestureRecognizer:_longPressRecognizer]; + + +// implement delegate +-(BOOL) shouldShowMenuAtPoint:(CGPoint)point +{ + NSIndexPath* indexPath = [self.collectionView indexPathForItemAtPoint:point]; + UICollectionViewCell* cell = [self.collectionView cellForItemAtIndexPath:indexPath]; + + return cell != nil; +} -// Implementing data source methods - (NSInteger) numberOfMenuItems { return 3; @@ -36,15 +47,32 @@ Sample app contains examples of how to add context menu for UIView and UICollect NSString* imageName = nil; switch (index) { case 0: - imageName = @"facebook"; + imageName = @"gp"; + break; + case 1: + imageName = @"p"; + break; + case 2: + imageName = @"t"; + break; + default: + break; + } + return [UIImage imageNamed:imageName]; +} + +- (UIImage *)highlightImageForItemAtIndex:(NSInteger)index { + NSString* imageName = nil; + switch (index) { + case 0: + imageName = @"gps"; break; case 1: - imageName = @"twitter"; + imageName = @"ps"; break; case 2: - imageName = @"google-plus"; + imageName = @"ts"; break; - default: break; } @@ -53,27 +81,59 @@ Sample app contains examples of how to add context menu for UIView and UICollect - (void) didSelectItemAtIndex:(NSInteger)selectedIndex forMenuAtPoint:(CGPoint)point { + NSIndexPath* indexPath = [self.collectionView indexPathForItemAtPoint:point]; + NSString* msg = nil; switch (selectedIndex) { case 0: - msg = @"Facebook Selected"; + msg = @"Google+ Selected"; break; case 1: - msg = @"Twitter Selected"; + msg = @"Pinterest Selected"; break; case 2: - msg = @"Google Plus Selected"; + msg = @"Twitter Selected"; break; - default: break; } + msg = [msg stringByAppendingFormat:@" for cell %ld", (long)indexPath.row +1]; + UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; + +} +- (NSString *)tipForItemAtIndex:(NSInteger)index { + NSString* tip = @""; + switch (index) { + case 0: + tip = @"Google+"; + break; + case 1: + tip = @"Pinterest"; + break; + case 2: + tip = @"Twitter"; + break; + default: + break; + } + return tip; } +- (UIView *)overlayViewAtPoint:(CGPoint)point { + NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:point]; + UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; + CGPoint origin = cell.frame.origin; + origin = [self.view convertPoint:origin fromView:self.collectionView]; + UIView *snap = [cell snapshotViewAfterScreenUpdates:NO]; + CGRect snapFrame = cell.bounds; + snapFrame.origin = origin; + snap.frame = snapFrame; + return snap; +} ``` ###Next Steps: @@ -84,3 +144,9 @@ Supporting configurations is one of the next steps. Any feature request is welco The MIT License + + +### Thanks: + +Icons from http://www.designcrawl.com/48-free-hollow-and-solid-fill-circle-icons/ + diff --git a/cmocv.gif b/cmocv.gif index d8f5eaf..979d234 100644 Binary files a/cmocv.gif and b/cmocv.gif differ diff --git a/cmov.gif b/cmov.gif index e460f9d..e96c508 100644 Binary files a/cmov.gif and b/cmov.gif differ