我需要将视图控制器推送到另一个视图控制器。
menuVC -> VC1 ->VC2
从菜单VC到VC1不需要动画,但从VC1到VC2以及从VC2到VC1需要发生翻转动画。
但是,当从VC2转到菜单VC时,不需要动画。
我正在使用以下代码:
(从如何推送带有翻转动画的视图控制器)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
FlashCardVC *flashCardVC = [[FlashCardVC alloc] init];
[self.navigationController pushViewController:flashCardVC animated:NO];
[UIView commitAnimations];
当我尝试执行上述操作时,屏幕将完全变为空白。
怎么了?
您现在真的应该使用基于块的动画了。此外,如果你正在从同一个故事板中的控制器实例化故事板控制器,你可以更容易地使用self.storyboard访问该故事板。
-(IBAction)flipToNext:(id)sender {
SecondController *next = [self.storyboard instantiateViewControllerWithIdentifier:@"Next"];
[self.navigationController pushViewController:next animated:NO];
[UIView transitionWithView:self.navigationController.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:nil];
}
在Swift 4.2中使用这些扩展
用于带有水平翻转动画的推送和弹出视图控制器
extension UINavigationController {
func pushViewControllerWithFlipAnimation(viewController:UIViewController){
self.pushViewController(viewController
, animated: false)
if let transitionView = self.view{
UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromLeft, animations: nil, completion: nil)
}
}
func popViewControllerWithFlipAnimation(){
self.popViewController(animated: false)
if let transitionView = self.view{
UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromRight, animations: nil, completion: nil)
}
}
}
答案很好:显示pushviewcontroller动画看起来像presentModalViewController
(代码)
//UIViewController *yourViewController = [[UIViewController alloc]init];</s>
[UIView beginAnimations: @"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController: yourViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
然而,这也产生了一个空白屏幕。
相反,如果你使用的是故事板,最好通过故事板实例化:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle bundleForClass:[self class]]];
YourViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"yourViewControllerID"];
您的ViewControllerID是在序列图像板中的viewcontroller类的标识检查器下设置的。