<

Popup Menu

>

Reference: Apple Developer Page

 

Setup:

  1. Create a Single View Application
  2. Add the QuartzCore.framework to the Xcode project

 

NMViewController.h

#import <UIKit/UIKit.h>
@interface NMViewController : UIViewController

{
IBOutlet UIScrollView *scrollView;

IBOutlet UIButton *openMenu;
int draw1;
}
- (IBAction)OpenMenu:(id)sender;

@property (retain, nonatomic) IBOutlet UIScrollView *scrollView;

@end


NMViewController.m


#import "NMViewController.h"

@interface NMViewController ()

@end

@implementation NMViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.


draw1 = 0;
scrollView.frame = CGRectMake(0, 300, 480, 55);
[scrollView setContentSize:CGSizeMake(480, 55)];

openMenu.frame = CGRectMake(220, 270, 60, 30);
}
- (IBAction)OpenMenu:(id)sender {
if (draw1 ==0) {
draw1 = 1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDelay:0.0];
[UIButton setAnimationCurve:UIViewAnimationCurveEaseOut];

scrollView.frame = CGRectMake(0, 245, 568, 55);
openMenu.frame = CGRectMake(220, 200, 60, 30);

[self.view bringSubviewToFront:scrollView];

[UIView commitAnimations];
} else {
draw1 = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
[UIButton setAnimationDelay:0.0];
[UIButton setAnimationCurve:UIViewAnimationCurveEaseOut];

scrollView.frame = CGRectMake(0, 300, 568, 55);
openMenu.frame = CGRectMake(220, 270, 60, 30);

[self.view bringSubviewToFront:scrollView];

[UIView commitAnimations];
}

@end

  1. Go to Mainstoryboard.storyboard and insert a 'View Controller' from object library.
  2. Add 'Scroll View' in 'View Controller' and resize it to 480 by 70 (in this project).
  3. Add 'Round Rect Button'.

 

  1. Link button in NMViewController.h. after "@interface FirstViewController : UIViewController"
  2. Make it an outlet and name it "openMenu"