如何从上到下动画视图?

时间:2012-08-03 12:18:26

标签: iphone objective-c

在我的应用程序中,我想从上到下启动UIViewController。因此,我从FirstViewController启动MyWebViewController(我需要设置动画),如下所示:

MyWebViewController *theWebViewController = [[MyWebViewController alloc] initWithFrame:self.view.bounds];
[self.view addSubview:theWebViewController.view];

并在MyWebViewController的loadView中我分配框架进行查看,如下所示;

- (void)loadView
{
    CGRect theFrame;
    theFrame = CGRectMake(0.0, 20.0, mFrame.size.width, 0.0);
    UIView *view = [[UIView alloc] init];
    view.frame = theFrame;
    self.view = view;
    [view release];
}

并在viewDidLoad中我按如下方式更改框架:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor clearColor];
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;

    [UIView beginAnimations:@"animateView" context: nil];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:0.5];
    self.view.frame = CGRectMake(0.0, 20.0, mFrame.size.width, mFrame.size.height-20.0);
    [UIView commitAnimations];
} 

但是动画没有发生。我甚至试过这个代码从下到上动画,它工作正常,反之亦然不工作。请任何人都能告诉我我做错了什么以及如何实现?< / p>

提前致谢!

1 个答案:

答案 0 :(得分:0)

我不认为将高度设置为0.相反:

- (void)loadView
{
    CGRect theFrame;
    theFrame = CGRectMake(0.0, -mframe.size.height + 20, mFrame.size.width, m.frame.size.height - 20);
    UIView *view = [[UIView alloc] init];
    view.frame = theFrame;
    self.view = view;
    [view release];
}

您希望在添加框架时将框架设置在视图的上方和外部。然后将其移动到动画中。