Skip to content

Commit f670fc0

Browse files
Merge pull request #37 from sunilsharma08/develop
Pod 2.0 release
2 parents 72de373 + 688ffc3 commit f670fc0

File tree

7 files changed

+186
-117
lines changed

7 files changed

+186
-117
lines changed

IGCMenu.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Pod::Spec.new do |s|
22
s.name = "IGCMenu"
3-
s.version = "1.2.1"
3+
s.version = "2.0.0"
44
s.summary = "Grid and Circular Menu for iOS."
55
s.description = "IGCMenu library gives easy way to create Grid and Circular menu in app.
66
This is light weight and highly customisable menu. Support iOS 7 and above."
77
s.homepage = "https://github.com/sunilsharma08/IGCMenu"
88
s.license = "MIT"
99
s.author = { "Sunil Sharma" => "[email protected]" }
10-
s.platform = :ios, "8.0"
10+
s.platform = :ios, "12.0"
1111
s.source = { :git => "https://github.com/sunilsharma08/IGCMenu.git", :tag => "#{s.version}" }
1212
s.source_files = "IGCMenu/**/*.{h,m}"
1313
s.requires_arc = true

IGCMenu/IGCMenu.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ typedef enum {
1717
None
1818
}IGCMenuBackgroundOptions;
1919

20+
typedef enum {
21+
Top,
22+
Bottom,
23+
}IGCMenuPositionOptions;
24+
2025
typedef enum {
2126
Opened,
2227
Closed
@@ -46,6 +51,7 @@ typedef enum {
4651
@property int maxColumn; //Maximium number of column,default is 3
4752
@property int menuHeight; //height = width ,default is 65
4853
@property IGCMenuBackgroundOptions backgroundType; //Default is BlurEffectDark
54+
@property IGCMenuPositionOptions positionStyle; //Default is Top
4955
@property UIColor *menuTitleColor; // Menu title color, default is white
5056
@property UIFont *menuTitleFont; // Menu title font, default is system regular 12
5157

@@ -55,3 +61,5 @@ typedef enum {
5561
-(void)hideGridMenu;
5662

5763
@end
64+
65+

IGCMenu/IGCMenu.m

Lines changed: 129 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ @implementation IGCMenu{
1818
NSMutableArray *menuButtonArray; //array of menu buttons
1919
NSMutableArray *menuNameLabelArray; //array of menu name label
2020
UIView *pMenuButtonSuperView;
21+
22+
int maxRow;
23+
__block CGFloat topMenuCenterY;
24+
CGFloat eachMenuWidth;
25+
CGFloat eachMenuVerticalSpace;
26+
BOOL isCircularMenu;
27+
BOOL isGridMenu;
2128
}
2229

2330
- (instancetype)init{
@@ -34,6 +41,14 @@ - (instancetype)init{
3441
self.backgroundType = BlurEffectDark;
3542
self.menuTitleColor = [UIColor whiteColor];
3643
self.menuTitleFont = [UIFont systemFontOfSize:12];
44+
self.positionStyle = Top;
45+
46+
//Observe orientation changes
47+
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
48+
[[NSNotificationCenter defaultCenter]
49+
addObserver:self selector:@selector(orientationChanged:)
50+
name:UIDeviceOrientationDidChangeNotification
51+
object:[UIDevice currentDevice]];
3752
}
3853
return self;
3954
}
@@ -83,7 +98,7 @@ - (void)createMenuButtons{
8398
[menuNameLabelArray addObject:menuNameLabel];
8499
}
85100

86-
// set accessibility label and add the label if present
101+
// Set accessibility label and add the label if present
87102
if (self.menuItemsAccessibilityLabelsArray.count > i) {
88103
menuButton.isAccessibilityElement = YES;
89104
menuButton.accessibilityLabel = self.menuItemsAccessibilityLabelsArray[i];
@@ -102,15 +117,15 @@ - (void)createMenuButtons{
102117
}
103118

104119
- (void)menuSuperViewBackground{
105-
if (pMenuButtonSuperView == nil) {
106-
pMenuButtonSuperView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
107-
pMenuButtonSuperView.tag = MENU_BACKGROUND_VIEW_TAG;
108-
}
109-
if (!self.menuSuperView) {
110-
self.menuSuperView = [self.menuButton superview];
111-
}
112-
[self.menuSuperView bringSubviewToFront:self.menuButton];
113-
[self.menuSuperView insertSubview:pMenuButtonSuperView belowSubview:self.menuButton];
120+
if (pMenuButtonSuperView == nil) {
121+
pMenuButtonSuperView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
122+
pMenuButtonSuperView.tag = MENU_BACKGROUND_VIEW_TAG;
123+
}
124+
if (!self.menuSuperView) {
125+
self.menuSuperView = [self.menuButton superview];
126+
}
127+
[self.menuSuperView bringSubviewToFront:self.menuButton];
128+
[self.menuSuperView insertSubview:pMenuButtonSuperView belowSubview:self.menuButton];
114129

115130
if (self.disableBackground){
116131
pMenuButtonSuperView.userInteractionEnabled = YES;
@@ -159,6 +174,7 @@ -(void)setBlurredView:(UIBlurEffectStyle) blurEffectStyle{
159174
}
160175

161176
- (void)showCircularMenu{
177+
isCircularMenu = true;
162178

163179
[self menuSuperViewBackground];
164180

@@ -168,25 +184,30 @@ - (void)showCircularMenu{
168184
//menuButton.center = CGPointMake(homeButtonCenter.x - radius * cos(angle * i), homeButtonCenter.y - radius * sin(angle * i));
169185

170186
for (int i = 1; i < menuButtonArray.count * 2; i=i+2) {
171-
172-
CGFloat angle = M_PI / (menuButtonArray.count * 2);
173187
[UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
174-
self->pMenuButtonSuperView.layer.opacity = 1.0;
175-
UIButton * menuButton = (UIButton *)[self->menuButtonArray objectAtIndex:i/2];
176-
menuButton.layer.opacity = 1.0;
177-
menuButton.center = CGPointMake(self.menuButton.center.x - self.menuRadius * cos(angle * i), self.menuButton.center.y - self.menuRadius * sin(angle * i));
178-
if (self->menuNameLabelArray.count > (i/2)) {
179-
UILabel *menuNameLabel = (UILabel *)[self->menuNameLabelArray objectAtIndex:i/2];
180-
menuNameLabel.layer.opacity = 1.0;
181-
menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5);
182-
}
188+
self->pMenuButtonSuperView.layer.opacity = 1.0;
189+
[self updateCircularMenuLayoutAtIndex:i];
183190
} completion:^(BOOL finished) {
184191
self.currentState = Opened;
185192
}];
186193
}
187194
}
188195

196+
- (void)updateCircularMenuLayoutAtIndex:(int)i{
197+
UIButton * menuButton = (UIButton *)[menuButtonArray objectAtIndex:i/2];
198+
menuButton.layer.opacity = 1.0;
199+
CGFloat angle = self.positionStyle == Top ? M_PI / (menuButtonArray.count * 2) : -M_PI / (menuButtonArray.count * 2);
200+
menuButton.center = CGPointMake(self.menuButton.center.x - self.menuRadius * cos(angle * i), self.menuButton.center.y - self.menuRadius * sin(angle * i));
201+
if (menuNameLabelArray.count > (i/2)) {
202+
UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:i/2];
203+
menuNameLabel.layer.opacity = 1.0;
204+
menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5);
205+
}
206+
}
207+
189208
- (void)hideCircularMenu{
209+
isCircularMenu = false;
210+
190211
[UIView animateWithDuration:ANIMATION_DURATION delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
191212
for (int i = 0; i < self->menuButtonArray.count; i++) {
192213
UIButton *menuButton = (UIButton *)[self->menuButtonArray objectAtIndex:i];
@@ -217,95 +238,127 @@ - (void)hideCircularMenu{
217238
}
218239

219240
-(void)showGridMenu{
241+
isGridMenu = true;
220242
[self menuSuperViewBackground];
221243
if (menuButtonArray.count <= 0) {
222244
[self createMenuButtons];
223245
}
224246

225-
int maxRow = ceilf(menuButtonArray.count /(float)self.maxColumn);
226-
__block CGFloat topMenuCenterY = self.menuButton.frame.origin.y - 10;
227-
CGFloat eachMenuVerticalSpace = 0;
228-
CGFloat eachMenuWidth = 0;
247+
[self setMenuButtonLayout];
248+
[UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
249+
self->pMenuButtonSuperView.layer.opacity = 1.0;
250+
[self updateGridMenuLayout];
251+
} completion:^(BOOL finished) {
252+
self.currentState = Opened;
253+
}];
254+
}
255+
256+
-(void)setMenuButtonLayout{
257+
maxRow = ceilf(menuButtonArray.count /(float)self.maxColumn);
258+
topMenuCenterY = self.menuButton.frame.origin.y - 10;
259+
eachMenuVerticalSpace = 0;
260+
eachMenuWidth = 0;
229261
if (menuButtonArray.count) {
230262
UIButton *menuButton = (UIButton *)menuButtonArray[0];
231-
eachMenuVerticalSpace = menuButton.frame.size.height + 20;
263+
eachMenuVerticalSpace = self.positionStyle == Top ? menuButton.frame.size.height + 20 : -(menuButton.frame.size.height + 20);
232264
eachMenuWidth = menuButton.frame.size.width;
233265
if (menuNameLabelArray.count) {
234266
UILabel *nameLabel = (UILabel *)menuNameLabelArray[0];
235267
eachMenuVerticalSpace = eachMenuVerticalSpace + nameLabel.frame.size.height;
236268
}
237269
topMenuCenterY = topMenuCenterY - (eachMenuVerticalSpace * maxRow) + menuButton.frame.size.height/2;
238270
}
239-
else{
240-
eachMenuVerticalSpace = 100.0;
271+
else {
272+
eachMenuVerticalSpace = self.positionStyle == Top ? 100.0 : -100.0;
241273
topMenuCenterY = topMenuCenterY - (eachMenuVerticalSpace * maxRow) + eachMenuVerticalSpace/3;
242274
}
275+
}
276+
277+
- (void)updateGridMenuLayout{
243278

244279
__block CGFloat distanceBetweenMenu = ((pMenuButtonSuperView.frame.size.width - (self.maxColumn*eachMenuWidth))/(self.maxColumn +1));
245-
246-
[UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
247-
self->pMenuButtonSuperView.layer.opacity = 1.0;
280+
int menuIndex = 0;
281+
//for each row
282+
for(int i = 1; i <= maxRow; i++,topMenuCenterY += eachMenuVerticalSpace) {
248283

249-
int menuIndex = 0;
250-
//for each row
251-
for(int i = 1; i <= maxRow; i++,topMenuCenterY += eachMenuVerticalSpace) {
252-
253-
int remainingMenuButton = self.maxColumn;
254-
//CGFloat menuCenterX = distanceBetweenMenu;
255-
256-
CGFloat menuCenterX;
257-
//for each column
258-
for (int j = 1; j <= remainingMenuButton; j++) {
259-
UIButton *menuButton = (UIButton *)[self->menuButtonArray objectAtIndex:menuIndex];
260-
menuButton.layer.opacity = 1.0;
261-
262-
menuCenterX = (distanceBetweenMenu *j) + (2*j - 1)*(menuButton.frame.size.width/2);
263-
if (i == maxRow) {
264-
remainingMenuButton = self->menuButtonArray.count % self.maxColumn;
265-
if (remainingMenuButton == 0) {
266-
remainingMenuButton = self.maxColumn;
267-
}
268-
menuCenterX = menuCenterX + ((self.maxColumn - remainingMenuButton)*(distanceBetweenMenu/2)) + (self.maxColumn - remainingMenuButton)*menuButton.frame.size.width/2;
269-
}
270-
menuButton.center = CGPointMake(menuCenterX, topMenuCenterY);
271-
272-
if (self->menuNameLabelArray.count > menuIndex) {
273-
UILabel *menuNameLabel = (UILabel *)[self->menuNameLabelArray objectAtIndex:menuIndex];
274-
menuNameLabel.layer.opacity = 1.0;
275-
menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5);
284+
int remainingMenuButton = self.maxColumn;
285+
//CGFloat menuCenterX = distanceBetweenMenu;
286+
287+
CGFloat menuCenterX;
288+
//for each column
289+
for (int j = 1; j <= remainingMenuButton; j++) {
290+
291+
UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:menuIndex];
292+
menuButton.layer.opacity = 1.0;
293+
294+
menuCenterX = (distanceBetweenMenu *j) + (2*j - 1)*(menuButton.frame.size.width/2);
295+
if (i == maxRow) {
296+
remainingMenuButton = self->menuButtonArray.count % self.maxColumn;
297+
if (remainingMenuButton == 0) {
298+
remainingMenuButton = self.maxColumn;
276299
}
277-
278-
menuIndex++;
300+
menuCenterX = menuCenterX + ((self.maxColumn - remainingMenuButton)*(distanceBetweenMenu/2)) + (self.maxColumn - remainingMenuButton)*menuButton.frame.size.width/2;
279301
}
302+
menuButton.center = CGPointMake(menuCenterX, topMenuCenterY);
303+
304+
if (menuNameLabelArray.count > menuIndex) {
305+
UILabel *menuNameLabel = (UILabel *)[menuNameLabelArray objectAtIndex:menuIndex];
306+
menuNameLabel.layer.opacity = 1.0;
307+
menuNameLabel.center = CGPointMake(menuButton.center.x, menuButton.frame.origin.y + menuButton.frame.size.height + (menuNameLabel.frame.size.height / 2) + 5);
308+
}
309+
310+
menuIndex++;
280311
}
281-
} completion:^(BOOL finished) {
282-
self.currentState = Opened;
283-
}];
312+
}
284313
}
285314

286315
-(void)hideGridMenu{
316+
isGridMenu = false;
287317
[self hideCircularMenu];
288318
}
289319

290320
- (void)menuButtonClicked:(UIButton *)sender{
291321
if ([self.delegate respondsToSelector:@selector(igcMenuSelected:atIndex:)]) {
292-
int index;
293-
NSInteger buttonTag = sender.tag;
294-
for (index = 0; index < menuButtonArray.count; index++) {
295-
UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:index];
296-
if (menuButton.tag == buttonTag) {
297-
NSString *menuName;
298-
if (self.menuItemsNameArray.count > index) {
299-
menuName = self.menuItemsNameArray[index];
300-
}
301-
if (self.delegate) {
302-
[self.delegate igcMenuSelected:menuName atIndex:index];
322+
int index;
323+
NSInteger buttonTag = sender.tag;
324+
for (index = 0; index < menuButtonArray.count; index++) {
325+
UIButton *menuButton = (UIButton *)[menuButtonArray objectAtIndex:index];
326+
if (menuButton.tag == buttonTag) {
327+
NSString *menuName;
328+
if (self.menuItemsNameArray.count > index) {
329+
menuName = self.menuItemsNameArray[index];
330+
}
331+
if (self.delegate) {
332+
[self.delegate igcMenuSelected:menuName atIndex:index];
333+
}
334+
break;
303335
}
304-
break;
305336
}
306337
}
307338
}
308-
}
309339

340+
//MARK: Orientation changes
341+
- (void)orientationChanged:(NSNotification *)note{
342+
UIDevice * device = note.object;
343+
switch(device.orientation){
344+
case UIDeviceOrientationPortrait:
345+
case UIDeviceOrientationLandscapeLeft:
346+
case UIDeviceOrientationLandscapeRight:
347+
[pMenuButtonSuperView setFrame: [UIScreen mainScreen].bounds];
348+
/* update menu animation */
349+
if (isCircularMenu){
350+
for (int i = 1; i < menuButtonArray.count * 2; i=i+2) {
351+
[self updateCircularMenuLayoutAtIndex:i];
352+
}
353+
} else if (isGridMenu){
354+
[self setMenuButtonLayout];
355+
[self updateGridMenuLayout];
356+
}
357+
break;
358+
default:
359+
break;
360+
};
361+
}
310362

311363
@end
364+

0 commit comments

Comments
 (0)