Giter Club home page Giter Club logo

prradialmenupopover's Introduction

PRRadialMenuPopover

Version License Platform

PRRadialMenu is a menu of buttons that extends from a point in a collection view. The menu is shown after a long press. The menu adjusts spacing based off the number of buttons. More updates coming soon.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Create an array of buttons to pass to the PopOverMenu. The menu will adjust to the number of buttons in the array. You must set an image for the highlated and normal state of the buttons. Below is an easy way to make circular buttons.

 CGRect frame = CGRectMake(0, 0, 44, 44);
 
 UIButton *buttonView = [[UIButton alloc]initWithFrame:frame];
 
 [buttonView setImage:[UIImage imageNamed:@"Image-3"] forState:UIControlStateNormal];
 [buttonView setImage:[UIImage imageNamed:@"Image-2"] forState:UIControlStateHighlighted];
 
 UIButton *buttonView2 = [[UIButton alloc]initWithFrame:frame];
 
 [buttonView2 setImage:[UIImage imageNamed:@"Image-3"] forState:UIControlStateNormal];
 [buttonView2 setImage:[UIImage imageNamed:@"Image-2"] forState:UIControlStateHighlighted];
 
 
 UIButton *buttonView3 = [[UIButton alloc]initWithFrame:frame];
 
 [buttonView3 setImage:[UIImage imageNamed:@"Image-3"] forState:UIControlStateNormal];
 [buttonView3 setImage:[UIImage imageNamed:@"Image-2"] forState:UIControlStateHighlighted];
 
 UIButton *buttonView4 = [[UIButton alloc]initWithFrame:frame];
 
 [buttonView4 setImage:[UIImage imageNamed:@"Image-1"] forState:UIControlStateNormal];
 [buttonView4 setImage:[UIImage imageNamed:@"Image"] forState:UIControlStateHighlighted];
 
 buttonView.layer.shadowColor = [UIColor colorWithWhite:0.0 alpha:1.0].CGColor;
 buttonView.layer.shadowOffset = CGSizeMake(0, 0);
 buttonView.layer.shadowRadius = 2.0;
 buttonView.layer.shadowOpacity = 0.4;
 
 buttonView2.layer.shadowColor = [UIColor colorWithWhite:0.0 alpha:1.0].CGColor;
 buttonView2.layer.shadowOffset = CGSizeMake(0, 0);
 buttonView2.layer.shadowRadius = 2.0;
 buttonView2.layer.shadowOpacity = 0.4;
 
 buttonView3.layer.shadowColor = [UIColor colorWithWhite:0.0 alpha:1.0].CGColor;
 buttonView3.layer.shadowOffset = CGSizeMake(0, 0);
 buttonView3.layer.shadowRadius = 2.0;
 buttonView3.layer.shadowOpacity = 0.4;
 
 buttonView4.layer.shadowColor = [UIColor colorWithWhite:0.0 alpha:1.0].CGColor;
 buttonView4.layer.shadowOffset = CGSizeMake(0, 0);
 buttonView4.layer.shadowRadius = 2.0;
 buttonView4.layer.shadowOpacity = 0.4;
NSArray *buttonArray = @[buttonView, buttonView2, buttonView3, buttonView4];

Next create the PRPopoverButtonMenu, assign the delegate, and add the gesture reconizer.

self.touchContextMenu = [[PRPopoverButtonMenu alloc] initWithFrame:self.collectionView.frame
     withButtons:buttons   //array of buttons  
     helpText:helpText     //array of text to be displayed above buttons
     controller:self       //CollectionViewController using the menu, needed to translate coords
     withOffset:offset     //offset betweeen navbar and top of view.  Used to detect if buttons will animate under nav bar
     labelSize:CGSizeMake(60, 20)  //size of labels above butons  
     withRadius:80       //radius from long press gesture to center of button
     angleScaler:2.1     //a scaler that adjusts the angle between the buttons
     initialThetaOffset:0]; //the initial offset of the arc where the buttons are placed.

 //set the delegate method
 self.touchContextMenu.delegate = self;
 
 //add the gesture reconizer to the collection view
 [self.collectionView addGestureRecognizer:self.touchContextMenu.longPressReconizer];
Add the two delegate methods to the collectionviewcontroller

Use this method to show the menu.  Make sure there is a valid cell on the point pushed.
shouldShowAtPoint:(CGPoint)point 

Use this method get the index of a pushed button. The Point returned is the point of the gesture.
didSelectButton:(NSInteger)index atPoint:(CGPoint)point 
  //Use this method to gurantee the location of the push was over a valid cell.
 - (BOOL) buttonMenu:(PRPopoverButtonMenu*)buttonMenu shouldShowAtPoint:(CGPoint)point {
         return ( [self.collectionView cellForItemAtIndexPath:[self.collectionView indexPathForItemAtPoint:point]] != nil );
 }
 
 //This method is called when the button a button has been pushed.
 - (void) buttonAtIndex:(PRPopoverButtonMenu *)buttonManager didSelectButton:(NSInteger)index atPoint:(CGPoint)point {
     NSIndexPath *cellPath = [self.collectionView indexPathForItemAtPoint:point];
     UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:cellPath];
 
     if ( !cell ) {
         return;
     }
 
     if ( index == 0 ) {
         NSLog(@"Action 1");
     } else if ( index == 1 ) {
         NSLog(@"Action 2");
     }else if(index == 2){
         NSLog(@"Action 3");
     }else {
         NSLog(@"Delete");
         self.cellNumber--;
         [self.collectionView deleteItemsAtIndexPaths:@[cellPath]];
     }

 }

Installation

PRRadialMenuPopover is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "PRRadialMenuPopover"

Author

Patrick Ryan, [email protected]

License

PRRadialMenuPopover is available under the MIT license. See the LICENSE file for more info.

prradialmenupopover's People

Contributors

pjryan93 avatar

Watchers

 avatar

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.