Coder Social home page Coder Social logo

ghcontextmenu's Introduction

#GHContextMenu - Pinterest like context menu control for iOS

alt tag alt tag alt tag

This is user friendly solution for showing context menu upon long press. It is inspired from the Pinterest iOS app

##How To Use

Sample app contains examples of how to add context menu for UIView and UICollectionView

  • Add GHContextMenuView headers and implementations to your project (2 files total).
  • Include with #import "GHContextMenuView.h" to use it wherever you need.
  • Set and implement the GHContextMenuViewDataSource to provide data about the pages.
  • Set and implement the GHContextMenuViewDelegate to receive callback upon selection.

Sample Code

// Creating
    GHContextMenuView* overlay = [[GHContextMenuView alloc] init];
    overlay.dataSource = self;
    overlay.delegate = self;
    
    UILongPressGestureRecognizer* _longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:overlay action:@selector(longPressDetected:)];
    [self.view addGestureRecognizer:_longPressRecognizer];

// Implementing data source methods
- (NSInteger) numberOfMenuItems
{
    return 3;
}

-(UIImage*) imageForItemAtIndex:(NSInteger)index
{
    NSString* imageName = nil;
    switch (index) {
        case 0:
            imageName = @"facebook";
            break;
        case 1:
            imageName = @"twitter";
            break;
        case 2:
            imageName = @"google-plus";
            break;
            
        default:
            break;
    }
    return [UIImage imageNamed:imageName];
}

- (void) didSelectItemAtIndex:(NSInteger)selectedIndex forMenuAtPoint:(CGPoint)point
{
    NSString* msg = nil;
    switch (selectedIndex) {
        case 0:
            msg = @"Facebook Selected";
            break;
        case 1:
            msg = @"Twitter Selected";
            break;
        case 2:
            msg = @"Google Plus Selected";
            break;
            
        default:
            break;
    }
    
    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];

}

###Next Steps: Supporting configurations is one of the next steps. Any feature request is welcome. Raise an issue with a feature tag and I will look into it

###License :

The MIT License

ghcontextmenu's People

Contributors

calvinchankf avatar infolock avatar morizotter avatar tapasya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ghcontextmenu's Issues

Returning NO from shouldShowMenuAtPoint pops menu in far upper left anyway and freezes UI

In the UICollectionView example, simply tap and hold in the gutter between cells (or add return NO; to the first line of shouldShowMenuAtPoint).

See the partial g+ button in the screenshot.

ios simulator screen shot apr 11 2014 1 37 45 pm

I have a hack-ish workaround:

if (self.dataSource != nil && [self.dataSource respondsToSelector:@selector(shouldShowMenuAtPoint:)] && ![self.dataSource shouldShowMenuAtPoint:pointInView]){
[self removeFromSuperview]; //rip self back out of view hierarchy, seems to correct.
return;
}

Would you like a pull on this, or do you have a better idea of what is going wrong and how to fix it?

Good stuff otherwise!
--DT

Add blur effect instead of basic background color

How would I add blur effect instead of just background color as the background of the menu? I tried several approaches but my code for filter just gets ignored. The issue is that inside GHContextMenuView I don't have self.view to add the subview.

its not working on single touch

i tried to change it to a single touch not long press touch to show the menu , but its not working !
can you help me with this ?

Returning a menu item of 1 results in a crash (divide by zero)

Quick fix in layout menu items:

  • (void) layoutMenuItems
    {
    [self.itemLocations removeAllObjects];

    CGSize itemSize = CGSizeMake(GHMenuItemSize, GHMenuItemSize);
    CGFloat itemRadius = sqrt(pow(itemSize.width, 2) + pow(itemSize.height, 2)) / 2;
    self.arcAngle = ((itemRadius * self.menuItems.count) / self.radius) * 1.5;

    NSUInteger count = self.menuItems.count;
    BOOL isFullCircle = (self.arcAngle == M_PI*2);
    NSUInteger divisor = (isFullCircle) ? count : count - 1;

    if (divisor == 0) divisor++; // bump divisor up to 1 if it is zero...

Make it more like Pinterest

#20 make it more like Pinterest

  • Add tool tip with show and hide animation
  • Add highlight image for highlight selection state
  • Add custom background color config
  • Add optional overlay view for preview selected Cell in Collection View
  • Remove item circle border and item background (Using highlight image instant)

Support for multiple orientations.

The context menu is not rendered properly when we change the device (iPad/iPhone) orientation. It always renders the context menu considering the orientation as normal Portrait in all the orientations due to which the context menu is wrongly rendered. It works fine in Portrait orientation but fails to give the same experience in other orientations. We would appreciate if you provide orientation support and help us by fixing this issue on priority. Thank you!

Feature - Change menu image depending on context

Hi,

I have a feature request based on what I'm trying to change in the context menu at the moment. If you imagine that one context menu option is to favourite an item, then long pressing on a collection view item should bring up a favourite icon if its not in your favourites or else bring up an icon for removing the favourite if it is already one. At present, the control is built up only on initialisation so can't be changed in this way.

I've looked at adding in a call to reloadData and animateMenu in the long press gesture handler but this doesn't seem to work in terms of regenerating the menu and I'm not really clear why not.

Also if you gave me a pointer in the right direction I could try to complete it myself.

Many thanks,
Rob

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.