您可以在将视图控制器推送到导航堆栈时尝试这样的操作:
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);