我需要将视图控制器推送到另一个视图控制器。
menuVC -> VC1 ->VC2
从menuVC到VC1不需要动画,但是从VC1到VC2以及从VC2到VC1需要翻转动画。
然而,当从VC2进入menuVC时,不需要动画。
我使用以下代码:
(来自how to push a viewController with flip animation)
[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];
当我尝试执行上述操作时,屏幕显示为空白。
有什么问题?
答案 0 :(得分:15)
你现在应该使用基于块的动画。此外,如果您从同一故事板中的控制器实例化故事板控制器,则可以使用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];
}
答案 1 :(得分:1)
很棒的答案: Showing pushviewcontroller animation look like 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"];
yourViewControllerID在yourviewcontroller类的身份检查器下的storyboard中设置。
答案 2 :(得分:1)
用于带有水平翻转动画的推和弹出视图控制器
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)
}
}
}