From 2a29ea30841b2b45ed07863bcdbe3971f878d54c Mon Sep 17 00:00:00 2001 From: Francesco Date: Tue, 3 Oct 2017 12:44:57 +0200 Subject: [PATCH 1/3] - Added device orientation observer - Added orientation changed method to handle menu layout - Added isCircularMenu or isGridMenu properties - Separated in different methods the layout set up for circular and grid menu --- IGCMenu/IGCMenu.m | 160 +++++++++++++++++++++++++------------- IGCMenuExample/Info.plist | 2 + 2 files changed, 107 insertions(+), 55 deletions(-) diff --git a/IGCMenu/IGCMenu.m b/IGCMenu/IGCMenu.m index 4c2e8d2..094fb99 100644 --- a/IGCMenu/IGCMenu.m +++ b/IGCMenu/IGCMenu.m @@ -18,6 +18,13 @@ @implementation IGCMenu{ NSMutableArray *menuButtonArray; //array of menu buttons NSMutableArray *menuNameLabelArray; //array of menu name label UIView *pMenuButtonSuperView; + + int maxRow; + __block CGFloat topMenuCenterY; + CGFloat eachMenuWidth; + CGFloat eachMenuVerticalSpace; + BOOL isCircularMenu; + BOOL isGridMenu; } - (instancetype)init{ @@ -31,6 +38,13 @@ - (instancetype)init{ self.menuRadius = 120; self.maxColumn = 3; self.backgroundType = BlurEffectDark; + + //observe orientation changes + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + [[NSNotificationCenter defaultCenter] + addObserver:self selector:@selector(orientationChanged:) + name:UIDeviceOrientationDidChangeNotification + object:[UIDevice currentDevice]]; } return self; } @@ -93,15 +107,15 @@ - (void)createMenuButtons{ } - (void)menuSuperViewBackground{ - if (pMenuButtonSuperView == nil) { - pMenuButtonSuperView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - pMenuButtonSuperView.tag = MENU_BACKGROUND_VIEW_TAG; - } - if (!self.menuSuperView) { + if (pMenuButtonSuperView == nil) { + pMenuButtonSuperView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + pMenuButtonSuperView.tag = MENU_BACKGROUND_VIEW_TAG; + } + if (!self.menuSuperView) { self.menuSuperView = [self.menuButton superview]; - } - [self.menuSuperView bringSubviewToFront:self.menuButton]; - [self.menuSuperView insertSubview:pMenuButtonSuperView belowSubview:self.menuButton]; + } + [self.menuSuperView bringSubviewToFront:self.menuButton]; + [self.menuSuperView insertSubview:pMenuButtonSuperView belowSubview:self.menuButton]; if (self.disableBackground){ pMenuButtonSuperView.userInteractionEnabled = YES; @@ -150,6 +164,7 @@ -(void)setBlurredView:(UIBlurEffectStyle) blurEffectStyle{ } - (void)showCircularMenu{ + isCircularMenu = true; [self menuSuperViewBackground]; @@ -159,23 +174,28 @@ - (void)showCircularMenu{ //menuButton.center = CGPointMake(homeButtonCenter.x - radius * cos(angle * i), homeButtonCenter.y - radius * sin(angle * i)); for (int i = 1; i < menuButtonArray.count * 2; i=i+2) { - - CGFloat angle = M_PI / (menuButtonArray.count * 2); [UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ pMenuButtonSuperView.layer.opacity = 1.0; - UIButton * menuButton = (UIButton *)[menuButtonArray objectAtIndex:i/2]; - menuButton.layer.opacity = 1.0; - menuButton.center = CGPointMake(self.menuButton.center.x - self.menuRadius * cos(angle * i), self.menuButton.center.y - self.menuRadius * sin(angle * i)); - if (menuNameLabelArray.count > (i/2)) { - UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:i/2]; - menuNameLabel.layer.opacity = 1.0; - menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5); - } + [self updateCircularMenuLayoutAtIndex:i]; }completion:nil]; } } +- (void)updateCircularMenuLayoutAtIndex:(int)i{ + UIButton * menuButton = (UIButton *)[menuButtonArray objectAtIndex:i/2]; + menuButton.layer.opacity = 1.0; + CGFloat angle = M_PI / (menuButtonArray.count * 2); + menuButton.center = CGPointMake(self.menuButton.center.x - self.menuRadius * cos(angle * i), self.menuButton.center.y - self.menuRadius * sin(angle * i)); + if (menuNameLabelArray.count > (i/2)) { + UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:i/2]; + menuNameLabel.layer.opacity = 1.0; + menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5); + } +} + - (void)hideCircularMenu{ + isCircularMenu = false; + [UIView animateWithDuration:ANIMATION_DURATION delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ for (int i = 0; i < menuButtonArray.count; i++) { UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:i]; @@ -205,15 +225,24 @@ - (void)hideCircularMenu{ } -(void)showGridMenu{ + isGridMenu = true; [self menuSuperViewBackground]; if (menuButtonArray.count <= 0) { [self createMenuButtons]; } - int maxRow = ceilf(menuButtonArray.count /(float)self.maxColumn); - __block CGFloat topMenuCenterY = self.menuButton.frame.origin.y - 10; - CGFloat eachMenuVerticalSpace = 0; - CGFloat eachMenuWidth = 0; + [self setMenuButtonLayout]; + [UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ + pMenuButtonSuperView.layer.opacity = 1.0; + [self updateGridMenuLayout]; + }completion:nil]; +} + +-(void)setMenuButtonLayout{ + maxRow = ceilf(menuButtonArray.count /(float)self.maxColumn); + topMenuCenterY = self.menuButton.frame.origin.y - 10; + eachMenuVerticalSpace = 0; + eachMenuWidth = 0; if (menuButtonArray.count) { UIButton *menuButton = (UIButton *)menuButtonArray[0]; eachMenuVerticalSpace = menuButton.frame.size.height + 20; @@ -228,48 +257,47 @@ -(void)showGridMenu{ eachMenuVerticalSpace = 100.0; topMenuCenterY = topMenuCenterY - (eachMenuVerticalSpace * maxRow) + eachMenuVerticalSpace/3; } +} + +- (void)updateGridMenuLayout{ - __block CGFloat distanceBetweenMenu = ((pMenuButtonSuperView.frame.size.width - (self.maxColumn*eachMenuWidth))/(self.maxColumn +1)); - - [UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ - pMenuButtonSuperView.layer.opacity = 1.0; + __block CGFloat distanceBetweenMenu = ((pMenuButtonSuperView.frame.size.width - (self.maxColumn*eachMenuWidth))/(self.maxColumn +1)); + int menuIndex = 0; + //for each row + for(int i = 1; i <= maxRow; i++,topMenuCenterY += eachMenuVerticalSpace) { - int menuIndex = 0; - //for each row - for(int i = 1; i <= maxRow; i++,topMenuCenterY += eachMenuVerticalSpace) { - - int remainingMenuButton = self.maxColumn; - //CGFloat menuCenterX = distanceBetweenMenu; + int remainingMenuButton = self.maxColumn; + //CGFloat menuCenterX = distanceBetweenMenu; + + CGFloat menuCenterX; + //for each column + for (int j = 1; j <= remainingMenuButton; j++) { + UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:menuIndex]; + menuButton.layer.opacity = 1.0; - CGFloat menuCenterX; - //for each column - for (int j = 1; j <= remainingMenuButton; j++) { - UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:menuIndex]; - menuButton.layer.opacity = 1.0; - - menuCenterX = (distanceBetweenMenu *j) + (2*j - 1)*(menuButton.frame.size.width/2); - if (i == maxRow) { - remainingMenuButton = menuButtonArray.count % self.maxColumn; - if (remainingMenuButton == 0) { - remainingMenuButton = self.maxColumn; - } - menuCenterX = menuCenterX + ((self.maxColumn - remainingMenuButton)*(distanceBetweenMenu/2)) + (self.maxColumn - remainingMenuButton)*menuButton.frame.size.width/2; - } - menuButton.center = CGPointMake(menuCenterX, topMenuCenterY); - - if (menuNameLabelArray.count > menuIndex) { - UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:menuIndex]; - menuNameLabel.layer.opacity = 1.0; - menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5); + menuCenterX = (distanceBetweenMenu *j) + (2*j - 1)*(menuButton.frame.size.width/2); + if (i == maxRow) { + remainingMenuButton = menuButtonArray.count % self.maxColumn; + if (remainingMenuButton == 0) { + remainingMenuButton = self.maxColumn; } - - menuIndex++; + menuCenterX = menuCenterX + ((self.maxColumn - remainingMenuButton)*(distanceBetweenMenu/2)) + (self.maxColumn - remainingMenuButton)*menuButton.frame.size.width/2; } + menuButton.center = CGPointMake(menuCenterX, topMenuCenterY); + + if (menuNameLabelArray.count > menuIndex) { + UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:menuIndex]; + menuNameLabel.layer.opacity = 1.0; + menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5); + } + + menuIndex++; } - }completion:nil]; + } } -(void)hideGridMenu{ + isGridMenu = false; [self hideCircularMenu]; } @@ -293,5 +321,27 @@ - (void)menuButtonClicked:(UIButton *)sender{ } } +//MARK: Orientation changes +- (void)orientationChanged:(NSNotification *)note{ + UIDevice * device = note.object; + switch(device.orientation){ + case UIDeviceOrientationPortrait: + case UIDeviceOrientationLandscapeLeft: + case UIDeviceOrientationLandscapeRight: + [pMenuButtonSuperView setFrame: [UIScreen mainScreen].bounds]; + /* update menu animation */ + if (isCircularMenu){ + for (int i = 1; i < menuButtonArray.count * 2; i=i+2) { + [self updateCircularMenuLayoutAtIndex:i]; + } + } else if (isGridMenu){ + [self setMenuButtonLayout]; + [self updateGridMenuLayout]; + } + break; + default: + break; + }; +} @end diff --git a/IGCMenuExample/Info.plist b/IGCMenuExample/Info.plist index 0ca4d80..40c6215 100644 --- a/IGCMenuExample/Info.plist +++ b/IGCMenuExample/Info.plist @@ -33,6 +33,8 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad From fd111ee0fb69af159a3fdc080ea2a1cf0b7477aa Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 4 Oct 2017 10:59:11 +0200 Subject: [PATCH 2/3] - added IGCMenuPositionOptions: Top or Bottom - updated angle property in circular menu - updated eachMenuVerticalSpace property in grid menu - added how to set menu position in ViewController --- IGCMenu/IGCMenu.h | 8 ++ IGCMenu/IGCMenu.m | 192 ++++++++++++++++++++------------ IGCMenuExample/ViewController.m | 7 +- 3 files changed, 136 insertions(+), 71 deletions(-) diff --git a/IGCMenu/IGCMenu.h b/IGCMenu/IGCMenu.h index f65e282..1a6268e 100644 --- a/IGCMenu/IGCMenu.h +++ b/IGCMenu/IGCMenu.h @@ -17,6 +17,11 @@ typedef enum { None }IGCMenuBackgroundOptions; +typedef enum { + Top, + Bottom, +}IGCMenuPositionOptions; + @protocol IGCMenuDelegate @optional @@ -39,6 +44,7 @@ typedef enum { @property int maxColumn; //Maximium number of column,default is 3 @property int menuHeight; //height = width ,default is 65 @property IGCMenuBackgroundOptions backgroundType; //Default is BlurEffectDark +@property IGCMenuPositionOptions positionStyle; //Default is Top -(void)showCircularMenu; -(void)hideCircularMenu; @@ -46,3 +52,5 @@ typedef enum { -(void)hideGridMenu; @end + + diff --git a/IGCMenu/IGCMenu.m b/IGCMenu/IGCMenu.m index 4c2e8d2..318d779 100644 --- a/IGCMenu/IGCMenu.m +++ b/IGCMenu/IGCMenu.m @@ -18,6 +18,13 @@ @implementation IGCMenu{ NSMutableArray *menuButtonArray; //array of menu buttons NSMutableArray *menuNameLabelArray; //array of menu name label UIView *pMenuButtonSuperView; + + int maxRow; + __block CGFloat topMenuCenterY; + CGFloat eachMenuWidth; + CGFloat eachMenuVerticalSpace; + BOOL isCircularMenu; + BOOL isGridMenu; } - (instancetype)init{ @@ -31,6 +38,14 @@ - (instancetype)init{ self.menuRadius = 120; self.maxColumn = 3; self.backgroundType = BlurEffectDark; + self.positionStyle = Top; + + //observe orientation changes + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + [[NSNotificationCenter defaultCenter] + addObserver:self selector:@selector(orientationChanged:) + name:UIDeviceOrientationDidChangeNotification + object:[UIDevice currentDevice]]; } return self; } @@ -93,15 +108,15 @@ - (void)createMenuButtons{ } - (void)menuSuperViewBackground{ - if (pMenuButtonSuperView == nil) { - pMenuButtonSuperView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - pMenuButtonSuperView.tag = MENU_BACKGROUND_VIEW_TAG; - } - if (!self.menuSuperView) { - self.menuSuperView = [self.menuButton superview]; - } - [self.menuSuperView bringSubviewToFront:self.menuButton]; - [self.menuSuperView insertSubview:pMenuButtonSuperView belowSubview:self.menuButton]; + if (pMenuButtonSuperView == nil) { + pMenuButtonSuperView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + pMenuButtonSuperView.tag = MENU_BACKGROUND_VIEW_TAG; + } + if (!self.menuSuperView) { + self.menuSuperView = [self.menuButton superview]; + } + [self.menuSuperView bringSubviewToFront:self.menuButton]; + [self.menuSuperView insertSubview:pMenuButtonSuperView belowSubview:self.menuButton]; if (self.disableBackground){ pMenuButtonSuperView.userInteractionEnabled = YES; @@ -150,6 +165,7 @@ -(void)setBlurredView:(UIBlurEffectStyle) blurEffectStyle{ } - (void)showCircularMenu{ + isCircularMenu = true; [self menuSuperViewBackground]; @@ -159,23 +175,28 @@ - (void)showCircularMenu{ //menuButton.center = CGPointMake(homeButtonCenter.x - radius * cos(angle * i), homeButtonCenter.y - radius * sin(angle * i)); for (int i = 1; i < menuButtonArray.count * 2; i=i+2) { - - CGFloat angle = M_PI / (menuButtonArray.count * 2); [UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ pMenuButtonSuperView.layer.opacity = 1.0; - UIButton * menuButton = (UIButton *)[menuButtonArray objectAtIndex:i/2]; - menuButton.layer.opacity = 1.0; - menuButton.center = CGPointMake(self.menuButton.center.x - self.menuRadius * cos(angle * i), self.menuButton.center.y - self.menuRadius * sin(angle * i)); - if (menuNameLabelArray.count > (i/2)) { - UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:i/2]; - menuNameLabel.layer.opacity = 1.0; - menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5); - } + [self updateCircularMenuLayoutAtIndex:i]; }completion:nil]; } } +- (void)updateCircularMenuLayoutAtIndex:(int)i{ + UIButton * menuButton = (UIButton *)[menuButtonArray objectAtIndex:i/2]; + menuButton.layer.opacity = 1.0; + CGFloat angle = self.positionStyle == Top ? M_PI / (menuButtonArray.count * 2) : -M_PI / (menuButtonArray.count * 2); + menuButton.center = CGPointMake(self.menuButton.center.x - self.menuRadius * cos(angle * i), self.menuButton.center.y - self.menuRadius * sin(angle * i)); + if (menuNameLabelArray.count > (i/2)) { + UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:i/2]; + menuNameLabel.layer.opacity = 1.0; + menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5); + } +} + - (void)hideCircularMenu{ + isCircularMenu = false; + [UIView animateWithDuration:ANIMATION_DURATION delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ for (int i = 0; i < menuButtonArray.count; i++) { UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:i]; @@ -205,18 +226,27 @@ - (void)hideCircularMenu{ } -(void)showGridMenu{ + isGridMenu = true; [self menuSuperViewBackground]; if (menuButtonArray.count <= 0) { [self createMenuButtons]; } - int maxRow = ceilf(menuButtonArray.count /(float)self.maxColumn); - __block CGFloat topMenuCenterY = self.menuButton.frame.origin.y - 10; - CGFloat eachMenuVerticalSpace = 0; - CGFloat eachMenuWidth = 0; + [self setMenuButtonLayout]; + [UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ + pMenuButtonSuperView.layer.opacity = 1.0; + [self updateGridMenuLayout]; + }completion:nil]; +} + +-(void)setMenuButtonLayout{ + maxRow = ceilf(menuButtonArray.count /(float)self.maxColumn); + topMenuCenterY = self.menuButton.frame.origin.y - 10; + eachMenuVerticalSpace = 0; + eachMenuWidth = 0; if (menuButtonArray.count) { UIButton *menuButton = (UIButton *)menuButtonArray[0]; - eachMenuVerticalSpace = menuButton.frame.size.height + 20; + eachMenuVerticalSpace = self.positionStyle == Top ? menuButton.frame.size.height + 20 : -(menuButton.frame.size.height + 20); eachMenuWidth = menuButton.frame.size.width; if (menuNameLabelArray.count) { UILabel *nameLabel = (UILabel *)menuNameLabelArray[0]; @@ -225,73 +255,95 @@ -(void)showGridMenu{ topMenuCenterY = topMenuCenterY - (eachMenuVerticalSpace * maxRow) + menuButton.frame.size.height/2; } else{ - eachMenuVerticalSpace = 100.0; + eachMenuVerticalSpace = self.positionStyle == Top ? 100.0 : -100.0; topMenuCenterY = topMenuCenterY - (eachMenuVerticalSpace * maxRow) + eachMenuVerticalSpace/3; } +} + +- (void)updateGridMenuLayout{ __block CGFloat distanceBetweenMenu = ((pMenuButtonSuperView.frame.size.width - (self.maxColumn*eachMenuWidth))/(self.maxColumn +1)); - - [UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ - pMenuButtonSuperView.layer.opacity = 1.0; + int menuIndex = 0; + //for each row + for(int i = 1; i <= maxRow; i++,topMenuCenterY += eachMenuVerticalSpace) { - int menuIndex = 0; - //for each row - for(int i = 1; i <= maxRow; i++,topMenuCenterY += eachMenuVerticalSpace) { - - int remainingMenuButton = self.maxColumn; - //CGFloat menuCenterX = distanceBetweenMenu; + int remainingMenuButton = self.maxColumn; + //CGFloat menuCenterX = distanceBetweenMenu; + + CGFloat menuCenterX; + //for each column + for (int j = 1; j <= remainingMenuButton; j++) { + UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:menuIndex]; + menuButton.layer.opacity = 1.0; - CGFloat menuCenterX; - //for each column - for (int j = 1; j <= remainingMenuButton; j++) { - UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:menuIndex]; - menuButton.layer.opacity = 1.0; - - menuCenterX = (distanceBetweenMenu *j) + (2*j - 1)*(menuButton.frame.size.width/2); - if (i == maxRow) { - remainingMenuButton = menuButtonArray.count % self.maxColumn; - if (remainingMenuButton == 0) { - remainingMenuButton = self.maxColumn; - } - menuCenterX = menuCenterX + ((self.maxColumn - remainingMenuButton)*(distanceBetweenMenu/2)) + (self.maxColumn - remainingMenuButton)*menuButton.frame.size.width/2; - } - menuButton.center = CGPointMake(menuCenterX, topMenuCenterY); - - if (menuNameLabelArray.count > menuIndex) { - UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:menuIndex]; - menuNameLabel.layer.opacity = 1.0; - menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5); + menuCenterX = (distanceBetweenMenu *j) + (2*j - 1)*(menuButton.frame.size.width/2); + if (i == maxRow) { + remainingMenuButton = menuButtonArray.count % self.maxColumn; + if (remainingMenuButton == 0) { + remainingMenuButton = self.maxColumn; } - - menuIndex++; + menuCenterX = menuCenterX + ((self.maxColumn - remainingMenuButton)*(distanceBetweenMenu/2)) + (self.maxColumn - remainingMenuButton)*menuButton.frame.size.width/2; + } + menuButton.center = CGPointMake(menuCenterX, topMenuCenterY); + + if (menuNameLabelArray.count > menuIndex) { + UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:menuIndex]; + menuNameLabel.layer.opacity = 1.0; + menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5); } + + menuIndex++; } - }completion:nil]; + } } -(void)hideGridMenu{ + isGridMenu = false; [self hideCircularMenu]; } - (void)menuButtonClicked:(UIButton *)sender{ if ([self.delegate respondsToSelector:@selector(igcMenuSelected:atIndex:)]) { - int index; - NSInteger buttonTag = sender.tag; - for (index = 0; index < menuButtonArray.count; index++) { - UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:index]; - if (menuButton.tag == buttonTag) { - NSString *menuName; - if (self.menuItemsNameArray.count > index) { - menuName = self.menuItemsNameArray[index]; - } - if (self.delegate) { - [self.delegate igcMenuSelected:menuName atIndex:index]; + int index; + NSInteger buttonTag = sender.tag; + for (index = 0; index < menuButtonArray.count; index++) { + UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:index]; + if (menuButton.tag == buttonTag) { + NSString *menuName; + if (self.menuItemsNameArray.count > index) { + menuName = self.menuItemsNameArray[index]; + } + if (self.delegate) { + [self.delegate igcMenuSelected:menuName atIndex:index]; + } + break; } - break; } } } -} +//MARK: Orientation changes +- (void)orientationChanged:(NSNotification *)note{ + UIDevice * device = note.object; + switch(device.orientation){ + case UIDeviceOrientationPortrait: + case UIDeviceOrientationLandscapeLeft: + case UIDeviceOrientationLandscapeRight: + [pMenuButtonSuperView setFrame: [UIScreen mainScreen].bounds]; + /* update menu animation */ + if (isCircularMenu){ + for (int i = 1; i < menuButtonArray.count * 2; i=i+2) { + [self updateCircularMenuLayoutAtIndex:i]; + } + } else if (isGridMenu){ + [self setMenuButtonLayout]; + [self updateGridMenuLayout]; + } + break; + default: + break; + }; +} @end + diff --git a/IGCMenuExample/ViewController.m b/IGCMenuExample/ViewController.m index 3d31f33..ae7b396 100644 --- a/IGCMenuExample/ViewController.m +++ b/IGCMenuExample/ViewController.m @@ -15,7 +15,7 @@ @interface ViewController () @implementation ViewController{ BOOL isMenuActive; IGCMenu *igcMenu; - + } - (void)viewDidLoad { @@ -35,7 +35,11 @@ -(void)setupMenu{ igcMenu.menuSuperView = self.view; //Pass reference of menu button super view igcMenu.disableBackground = YES; //Enable/disable menu background igcMenu.numberOfMenuItem = 5; //Number of menu items to display + + //Menu background. It can be BlurEffectExtraLight,BlurEffectLight,BlurEffectDark,Dark or None igcMenu.backgroundType = BlurEffectDark; + //Menu position style on Top or Bottom of menu button, default is Top + //igcMenu.positionStyle = Bottom; /* Optional Pass name of menu items @@ -119,3 +123,4 @@ - (void)didReceiveMemoryWarning { } @end + From 688ffc35159faf9b7ce3f88299dfa69506fd92b6 Mon Sep 17 00:00:00 2001 From: Sunil Sharma Date: Wed, 31 Jan 2024 01:15:49 +0530 Subject: [PATCH 3/3] Updated minimum pod version --- IGCMenu.podspec | 4 ++-- README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/IGCMenu.podspec b/IGCMenu.podspec index 5608a6b..bfd263b 100644 --- a/IGCMenu.podspec +++ b/IGCMenu.podspec @@ -1,13 +1,13 @@ Pod::Spec.new do |s| s.name = "IGCMenu" - s.version = "1.2.1" + s.version = "2.0.0" s.summary = "Grid and Circular Menu for iOS." s.description = "IGCMenu library gives easy way to create Grid and Circular menu in app. This is light weight and highly customisable menu. Support iOS 7 and above." s.homepage = "https://github.com/sunilsharma08/IGCMenu" s.license = "MIT" s.author = { "Sunil Sharma" => "sunilsharma.ss08@gmail.com" } - s.platform = :ios, "8.0" + s.platform = :ios, "12.0" s.source = { :git => "https://github.com/sunilsharma08/IGCMenu.git", :tag => "#{s.version}" } s.source_files = "IGCMenu/**/*.{h,m}" s.requires_arc = true diff --git a/README.md b/README.md index d7a2236..d75d481 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # IGCMenu IGCMenu library gives easy way to create **Grid** and **Circular** menu in app. -This is light weight and highly customisable menu.Support iOS 7 and above. +This is light weight and highly customisable menu.Support iOS 12 and above. For swift check [swift branch](https://github.com/sunilsharma08/IGCMenu/tree/swift) @@ -35,7 +35,7 @@ For swift check [swift branch](https://github.com/sunilsharma08/IGCMenu/tree/swi You can use [CocoaPods](http://cocoapods.org/) to install `IGCMenu` by adding it to your `Podfile`: ```Ruby -platform :ios, '8.0' +platform :ios, '12.0' target 'TargetName' do pod 'IGCMenu'