在视图控制器之间转换时自定义动画

时间:2015-09-22 06:43:05

标签: ios objective-c cocoa-touch uikit core-animation

我想在这样的视图控制器之间创建转换。 https://www.dropbox.com/s/qatwqaq2mowocsg/Transitions%20Controller.gif?dl=0

我已使用以下代码创建转换但无法实现以下结果。

self.settings = [self.storyboard instantiateViewControllerWithIdentifier:@"settings"];
CATransition* transition = [CATransition animation];

transition.duration = 0.4;
transition.type = kCATransitionPush;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.subtype=kCATransitionFromRight;


[[self navigationController].view.layer addAnimation:transition forKey:kCATransition];
[[self navigationController] pushViewController:self.settings animated:NO];

3 个答案:

答案 0 :(得分:1)

您可以尝试以下代码:

self.settings = [self.storyboard instantiateViewControllerWithIdentifier:@"settings"];

[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:
 UIViewAnimationTransitionFlipFromRight
                       forView:self.navigationController.view cache:NO];


[self.navigationController pushViewController:self.settings animated:YES];
[UIView commitAnimations];

答案 1 :(得分:0)

从iOS7开始,您可以自定义系统方法pushViewController和presentViewController的过渡效果。例如,如果您需要自定义推送效果,则UINavigationControllerDelegate中有一个名为

的方法
- (id<UIViewControllerAnimatedTransitioning> _Nullable)navigationController:(UINavigationController * _Nonnull)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController * _Nonnull)fromVC toViewController:(UIViewController * _Nonnull)toVC

将自定义动画添加到fromVC的视图中,并在适当的时间显示toVC的视图

答案 2 :(得分:0)

虽然它不是代表while ((c=getchar())!=EOF) { if(isalpha(c) || isspace(c))// isspace allow '\t' => c == ' ' || c == '\n' putchar(toupper(c)); } 的可直接实现的代码块,但此博客应引导您完成创建自定义转换的步骤:http://blog.dadabeatnik.com/2013/10/13/custom-segues/