2010-08-16 71 views
0

我在正常视图内有一个tableview和一个普通的视图(比方说view 2)。全部由Interface Builder构建。视图2位于桌面视图上方,需要在视图加载时从上方呈现动画。按下按钮时,视图会再次消失。我怎样才能做到这一点?添加动画视图

谢谢

回答

1

您必须在自定义动画块中为此设置动画。它应该是相当简单.. 设置您的视图的框架,以便它在屏幕和不可见上面:

[yourView setFrame:CGRectMake(0, -480, 320, 480)]; 

在动画块只需更改您的视图的帧动画块:

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:GROW_AND_MOVE_ANIMATION_DURATION_SECONDS]; 
[yourView setFrame:CGRectMake(0, 0, 320, 480)]; 
[UIView commitAnimations]; 

要关闭它/让它消失使用同样的动画与前一帧:

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:GROW_AND_MOVE_ANIMATION_DURATION_SECONDS]; 
[yourView setFrame:CGRectMake(0, -480, 320, 480)]; 
[UIView commitAnimations]; 

但在此之前考虑是否必须从顶部带上它,因为如果布林为模态的视图满足您的要求,从底部晋它,你可以很容易使用UIViewController的方法:

- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated 

好运。

+0

但presentModalViewController方法将无法正常工作,因为我认为这是一个UIView,而不是一个UIViewController(尽管我不确定) – 2010-08-16 14:45:18

+0

谢谢你的回答。 我真的这样做,它的工作原理: [UIView beginAnimations:nil context:NULL]; \t [UIView setAnimationDuration:1]; \t [UIView setAnimationDelegate:self]; \t CGAffineTransform transformView = myView.transform; \t transformView = CGAffineTransformTranslate(transformView,0,+210); \t myView.transform = transformView; 我改变了界面构建器中的坐标。 – DanielaM 2010-08-16 15:20:52