Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay animating view within ViewController
    primarykey
    data
    text
    <p>EDITED:</p> <p>I had created a slide in menu for my view and it works as i wanted, this was the original guide that I used.</p> <p><a href="http://www.youtube.com/watch?v=79ZQDzzOHLk" rel="nofollow">http://www.youtube.com/watch?v=79ZQDzzOHLk</a></p> <p>My goal was to get this programmed once in a class and get it to work on any view controller that i decided to call it in.</p> <p>Thanks to @harsh.prasad and some additional research I have managed to get this to work to a point where it works as I want apart apart from linking buttons on to it.</p> <p>So to update this question in the hope it may help someone else.</p> <p>This is what I did:</p> <p>I created a UIView class and called it MenuOne.</p> <p>MenuOne.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface TFMenuOne : UIView { // Pop Up Menu IBOutlet UIScrollView *scrollView; IBOutlet UIButton *openMenu; int draw1; IBOutlet UIButton *backButton; } // Pop Up Menu - (IBAction)openMenu_clicked:(id)sender; // Reset draw1 to 0 - (void) resetView: (id) sender; @property (retain, nonatomic) IBOutlet UIScrollView *scrollView; @end </code></pre> <p>MenuOne.m</p> <pre><code>#import "TFMenuOne.h" @implementation TFMenuOne @synthesize scrollView; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { draw1 = 0; scrollView = [[UIScrollView alloc] init]; [scrollView setBackgroundColor:[UIColor whiteColor]]; [scrollView setFrame:CGRectMake(0, 315, 568, 5)]; [scrollView setContentSize:CGSizeMake(568, 5)]; backButton = [[UIButton alloc] init]; [backButton setBackgroundColor:[UIColor greenColor]]; backButton.frame = CGRectMake(224, 350, 120, 30); openMenu = [[UIButton alloc] init]; [openMenu setBackgroundImage:[UIImage imageNamed:@"menu-button-@2.png"] forState:UIControlStateNormal]; openMenu.adjustsImageWhenHighlighted = NO; [openMenu addTarget:self action:@selector(openMenu_clicked:) forControlEvents:UIControlEventTouchUpInside]; openMenu.frame = CGRectMake(256, 269, 64, 46); [self addSubview:scrollView]; [self addSubview:backButton]; [self addSubview:openMenu]; } return self; } // Allow for touch even through transparent View class -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { for (UIView *view in self.subviews) { if (!view.hidden &amp;&amp; view.userInteractionEnabled &amp;&amp; [view pointInside:[self convertPoint:point toView:view] withEvent:event]) return YES; } return NO; } - (void) resetView: (id) sender { draw1 = 1; [self openMenu_clicked:sender]; } - (IBAction)openMenu_clicked:(id)sender { if (draw1 == 0) { draw1 = 1; [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ scrollView.frame = CGRectMake(0, 260, 568, 60); } completion:^(BOOL finished) { }]; [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ openMenu.frame = CGRectMake(256, 214, 64, 46); } completion:^(BOOL finished) { }]; [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ backButton.frame = CGRectMake(224, 275, 120, 30); } completion:^(BOOL finished) { }]; } else { draw1 = 0; [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ scrollView.frame = CGRectMake(0, 315, 568, 5); } completion:^(BOOL finished) { }]; [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ openMenu.frame = CGRectMake(256, 269, 64, 46); } completion:^(BOOL finished) { }]; [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ backButton.frame = CGRectMake(224, 350, 120, 30); } completion:^(BOOL finished) { }]; } } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end </code></pre> <p>After a lot of trial and error, in order to get this UIView class to appear on multiple ViewControllers I call the view like this in the m file of the view controller. The obstacles I ran in to was that the menu would open but when I left the view controller to go to another view controller the menu would be in the state it was in when i left, it wouldn't reset back to closed. The code below covered that thanks again to @harsh.prasad. I also managed to get the menu to animate in.</p> <pre><code>@interface TFMapViewController () { TFMenuOne *menuView; } @end @implementation TFMapViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization [menuView resetView:nil]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. menuView = [[TFMenuOne alloc] initWithFrame:CGRectMake(0, 51, 568, 320)]; [self.view addSubview:menuView]; } - (void) viewDidAppear:(BOOL)animated { [UIView animateWithDuration:0.5 delay:0.5 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ menuView.frame = CGRectMake(0, 0, 568, 320); } completion:^(BOOL finished) { }]; } - (void) viewDidDisappear:(BOOL)animated { [menuView resetView:nil]; [UIView animateWithDuration:0.0 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ menuView.frame = CGRectMake(0, 51, 568, 320); } completion:^(BOOL finished) { }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } // Allows for Exit button to work - (IBAction)returned:(UIStoryboardSegue *)segue { } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload