Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 7    Views: 155

Susan Metoxen
buzztouch Evangelist
Profile
Posts: 1706
Reg: May 01, 2011
Hopkins, Minnes...
26,260
08/16/14 11:47 AM (10 years ago)

Slide Out Context Menu

If you would like your Context Menu to slide in and out instead of fade in and out, all you have to do is replace two methods in the appDelegate file (@line 525) with the code below. Kittsy helped me with this code. (If you aren't ready to modify the code yourself, let me know and I can help you find a qualified Buzztouch developer for hire.) /*Slide Out Context Menu--showContextMenu and hideContextMenu methods. Replace these two methods entirely with the two methods below: showContextMenu and HideContext Menu. */ //showContextMenu... -(void)showContextMenu{ [BT_debugger showIt:self message:@"showContextMenu"]; //show the context menu's view... if(self.contextMenu != nil){ //current nav controller and view controller... BT_navController *theNavController = [self getNavigationController]; //position depends on device orientation UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; //if the view isn't already on the nav controller..add it. contextMenu view has tag "888" BOOL haveContextMenu = FALSE; for(UIView *view in theNavController.view.subviews) { if([view tag] == 888){ haveContextMenu = TRUE; break; } } //add the subview to this controller if we don't already have it if(!haveContextMenu){ [theNavController.view addSubview:[self.contextMenu view]]; } //make mask and menu in context view full size... [self.contextMenu.mask setFrame:theNavController.view.bounds]; [self.contextMenu.menuTable setFrame:theNavController.view.bounds]; //bring context menu's view to the front so we can see it when it fades in.. [theNavController.view bringSubviewToFront:[self.contextMenu view]]; //position the menu's list to top right... int w = [self.rootDevice deviceWidth]; int h = [self.rootDevice deviceHeight]; //if landscape mode the values are opposite... if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){ w = [self.rootDevice deviceHeight]; h = [self.rootDevice deviceWidth]; }else{ w = [self.rootDevice deviceWidth]; h = [self.rootDevice deviceHeight]; } //table top position... int tableTop = 0; //need status bar and navBar style to determine table top position... BT_item *tmpScreenData = [self.rootApp currentScreenData]; NSString *tmpStatusStyle = [BT_strings getStyleValueForScreen:tmpScreenData nameOfProperty:@"statusBarStyle" defaultValue:@""]; NSString *tmpNavBarStyle = [BT_strings getStyleValueForScreen:tmpScreenData nameOfProperty:@"navBarStyle" defaultValue:@""]; if(![tmpStatusStyle isEqualToString:@"hidden"]){ tableTop += 20; } if(![tmpNavBarStyle isEqualToString:@"hidden"]){ //iOS 7 uses a different nav. bar height... if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1){ tableTop += 45; }else{ tableTop += 44; } } //if device is landscape, remove some pixels... if(tableTop > 0){ if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){ tableTop -= 12; //if this is an iPad, add a few more pixels... if([self.rootDevice isIPad]){ tableTop += 12; } } } //set table size... [contextMenu.menuTable setFrame:CGRectMake(0, tableTop, (w *.5), 350)]; //move the table to the right of the screen... CGRect frame = contextMenu.menuTable.frame; CGRect startFrame = contextMenu.menuTable.frame; CGFloat xPosition = w * .5; //when landscape the w is the height... if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){ xPosition = h / 2; } frame.origin.x = xPosition; startFrame.origin.x = CGRectGetWidth(window.bounds); contextMenu.menuTable.frame = startFrame; //animation block... [UIView animateWithDuration:0.25 animations:^{ [self.contextMenu.view setHidden:FALSE]; self.contextMenu.view.alpha = 0.0; self.contextMenu.view.alpha = 1.0; contextMenu.menuTable.frame = frame; } completion:^(BOOL finished){ //ignore... }]; } } //hideContextMenu... -(void)hideContextMenu{ [BT_debugger showIt:self message:[NSString stringWithFormat:@"hideContextMenu %@", @""]]; //move the table to the right of the screen... CGRect startFrame = contextMenu.menuTable.frame; startFrame.origin.x = CGRectGetWidth(window.bounds); //move the the context menu off the screen and hide it if(self.contextMenu != nil){ //animate context menu... [UIView animateWithDuration:0.25 animations:^{ // self.contextMenu.view.alpha = 1.0; self.contextMenu.view.alpha = 0.0; contextMenu.menuTable.frame = startFrame; } completion:^(BOOL finished){ //ignore... }]; } }
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
08/16/14 12:22 PM (10 years ago)
Thank you Susan (and presumably Kittsy), I will give this a play. Cheers, Alan
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
08/16/14 12:29 PM (10 years ago)
Nice!! Thanks :)
 
aquila198
buzztouch Evangelist
Profile
Posts: 473
Reg: Jul 22, 2011
location unknow...
10,330
like
08/16/14 03:04 PM (10 years ago)
excellent share! thanks Susan!
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
08/16/14 04:24 PM (10 years ago)
Love it, love it, luv it. Ya know that the Android lovers will be piping up soon...:-) -- Niraj
 
Adam
Aspiring developer
Profile
Posts: 247
Reg: Oct 23, 2010
Southern Califo...
4,470
like
08/16/14 08:05 PM (10 years ago)
Thanks for posting. Adam
 
epicweb
Aspiring developer
Profile
Posts: 159
Reg: Aug 30, 2012
Glen Carbon
4,990
like
09/09/14 04:55 PM (9 years ago)
anyone know how to make the context menu height 100%?
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
09/09/14 06:34 PM (9 years ago)
I am guessing you should modify the frame parameters. Play with this line: [contextMenu.menuTable setFrame:CGRectMake(0, tableTop, (w *.5), 350)]; That is x,y,w,h Try replacing 350 with h - tableTop, that will set the height of the table to be the device height minus height of the Statusbar and height of Navbar. No promises. Just guesses from reading Susan-Kittsy code on this post. -- Niraj
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.