objective-c - 如何为 UIView 制作与 presentModalViewController 相同的动画(即 [self presentModalViewController :child animated:YES];)

标签 objective-c animation uiview xcode4 ios4

我是 ios 开发的新手,现在我正在我的应用程序上做一些动画。在我的应用程序中,主视图底部有一个菜单,有两个按钮,一个用于隐藏菜单,另一个用于显示菜单。我的需要菜单的显示和隐藏功能是否正常工作 [self presentModalViewController:menuView animated:YES];[self dismissModalViewControllerAnimated:YES]; 函数(即点击显示按钮,从 main 底部弹出 menuView查看并单击隐藏按钮,向下移动菜单 View )。我知道基本的动画,比如:

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

[UIView setAnimationCurve:UIViewAnimationOptionOverrideInheritedCurve];

[UIView setAnimationDuration:1.0];

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

[UIView commitAnimations];

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

最佳答案

当您点击 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];
}

隐藏起来,

- (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];
}

关于objective-c - 如何为 UIView 制作与 presentModalViewController 相同的动画(即 [self presentModalViewController :child animated:YES];),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9494309/

相关文章:

Javascript AppendTo 动画不起作用

javascript - 如何使用 javascript/jquery 实现此动画?

objective-c - UIBezierPath - 动画填充

swift - 在 if else 语句中满足条件时不隐藏 UIView

ios - dyld : Library not loaded: @rpath/libswiftCore. dylib 问题仅在模拟器上持续存在

ios - 带有 NSUserActivity 的 Siri 快捷方式 - 事件删除不起作用

android - 更改 Activity 时如何更改默认动画?

objective-c - block 和内存管理

objective-c - iTunes 中的应用程序类型

ios - 在 iOS 8 中显示隐藏键盘时编辑 UIView 的边界