1

我正在尝试开发一个 iphone 应用程序。我知道如何在推入导航堆栈时从左向右滑动视图。但我的要求是在推入导航堆栈时从上到下为视图设置动画。那么该怎么做呢?

我正在搜索谷歌,但没有找到任何令人满意的结果。如果有人知道...请告诉我该怎么做。

info = [[InfoView alloc] initWithNibName:@"InfoView" bundle:nil];   
[self.navigationController pushViewController:info animated:YES];
4

1 回答 1

2

您可以在将视图控制器推送到导航堆栈时尝试这样的操作:

       SecondViewController *VC2 = [[SecondViewController alloc]init];
       VC2.nameSupplied = self.nameField.text;
       CGPoint mycenter = VC2.view.center;
       CGPoint navCenter = self.navigationController.navigationBar.center;
       VC2.view.center = CGPointMake(mycenter.x , mycenter.y - VC2.view.frame.size.height);
       self.navigationController.navigationBar.center = CGPointMake(navCenter.x, navCenter.y - self.navigationController.navigationBar.frame.size.height);
      [self.navigationController pushViewController:VC2 animated:NO];
      [UIView animateWithDuration:0.5
                            delay:0
                          options: UIViewAnimationCurveEaseOut
                       animations:^{
                                  VC2.view.center = mycenter;
                                  self.navigationController.navigationBar.center = navCenter;
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Animation Done!");
                 }];

但是,如果您只想在同一个视图控制器中显示另一个视图(从上到下移动),您可以像这样使用UIView的 transform 属性:

self.secondView.transform = CGAffineTransformMakeTranslation(0, secondView.frame.size.height);
于 2012-08-06T05:52:21.753 回答