我想用自定义模态动画推送ViewController。我更喜欢使用“Cover Vertical”动画。 “封面垂直”是否有MDAVSCLI : error : The edge module has not been pre-compiled for node.js version v4.1.1. You must build a custom version of edge.node. Please refer to https://github.com/tjanczuk/edge for building instructions.
?
UIViewAnimationOption
将[self.navigationController pushViewController:myViewController animated:NO];
[UIView transitionWithView:self.navigationController.view duration:1 options:UIViewAnimationOptionCurveEaseIn animations:nil completion:nil];
替换为......?或者有更好的方法吗?
答案 0 :(得分:0)
您需要使用动画控制器。设置它的代码如下所示:
- (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController (UIViewController *)source
{
return self.animationController;
}
- (id )animationControllerForDismissedController:(UIViewController *)dismissed {
self.animationController.isPresenting = NO;
return self.animationController;
}
然后您需要使用以下方法确定您是否正在展示或解雇:
-(void)animateTransition:(id)transitionContext{
if(self.isPresenting){
[self executePresentationAnimation:transitionContext];
}
else{
[self executeDismissalAnimation:transitionContext];
}
}
最后,您定义了动画,以下代码将从顶部推送视图作为模态视图:
-(void)executePresentationAnimation:(id)transitionContext{
UIView* inView = [transitionContext containerView];
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
[inView addSubview:toViewController.view];
CGPoint centerOffScreen = inView.center;
centerOffScreen.y = (-1)*inView.frame.size.height;
toViewController.view.center = centerOffScreen;
[UIView animateWithDuration:self.presentationDuration delay:0.0f usingSpringWithDamping:0.4f initialSpringVelocity:6.0f options:UIViewAnimationOptionCurveEaseIn animations:^{
toViewController.view.center = inView.center;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
当你解雇相反时,应该发生:
-(void)executeDismissalAnimation:(id)transitionContext{
UIView* inView = [transitionContext containerView];
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
[inView insertSubview:toViewController.view belowSubview:fromViewController.view];
CGPoint centerOffScreen = inView.center;
centerOffScreen.y = (-1)*inView.frame.size.height;
[UIView animateKeyframesWithDuration:self.dismissalDuration delay:0.0f options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5 animations:^{
CGPoint center = fromViewController.view.center;
center.y += 50;
fromViewController.view.center = center;
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{
fromViewController.view.center = centerOffScreen;
}];
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}