Search code examples
objective-canimationuiviewxcode4ios4

how to animate a UIView same as the working of presentModalViewController ( ie [self presentModalViewController:child animated:YES];)


I am new in ios development, Now i am doing some animation on my application.In my application has one menu on the bottom of main view and have two button one for hide the menu and other for show the menu .My needs is the show and hide function of menu is working like the [self presentModalViewController:menuView animated:YES]; and [self dismissModalViewControllerAnimated:YES]; function(ie. click the show button ,pop the menuView from the bottom of main view and click the hide button ,move down the menuView ) . I know the basic animation like:

[UIView beginAnimations:@"ShowHideView" context:nil];

[UIView setAnimationCurve:UIViewAnimationOptionOverrideInheritedCurve];

[UIView setAnimationDuration:1.0];

[UIView setAnimationDelegate:self];
[menuView setAlpha:0];

[UIView commitAnimations];

If any body know ,please help me.


Solution

  • When you tap showMenuView, do as following,

    - (IBAction)showView:(id)sender 
    {
        [self.view addSubview: menuView];
        CGRect rect = menuView.frame;
        rect.origin.y = 480;
        menuView.frame = rect;
        [UIView beginAnimations:@"ShowView" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.5]; 
        rect.origin.y = 0;
        menuView.frame = rect;
        [UIView commitAnimations];
    }
    

    And to hide,

    - (IBAction)hideView:(id)sender 
    {
        CGRect rect = menuView.frame;
        [UIView beginAnimations:@"HideView" context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.5]; 
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
        rect.origin.y = 480;
        menuView.frame = rect;
        [UIView commitAnimations];
    }
    
    - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
    {
        [menuView removeFromSuperview];
    }