如何动画UIView与presentModalViewController的工作相同(即[self presentModalViewController:child animated:YES];)

Joh*_*ohn 3 animation objective-c uiview ios4 xcode4

我是ios开发的新手,现在我在我的应用程序上做了一些动画.我的应用程序在主视图底部有一个菜单,有两个按钮用于隐藏菜单,另外用于显示菜单.我需要的是节目菜单的隐藏功能 [self presentModalViewController:menuView animated:YES];[self dismissModalViewControllerAnimated:YES];功能一样(即单击显示按钮,从主视图底部弹出menuView,然后单击隐藏按钮,向下移动菜单视图).我知道基本动画如:

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

[UIView setAnimationCurve:UIViewAnimationOptionOverrideInheritedCurve];

[UIView setAnimationDuration:1.0];

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

[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

如果有人知道,请帮助我.

Ila*_*ian 6

点击showMenuView时,请执行以下操作,

- (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];
}
Run Code Online (Sandbox Code Playgroud)

而隐藏,

- (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];
}
Run Code Online (Sandbox Code Playgroud)