iOS7中的UIViewControllerAnimatedTransitioning - 未调用viewWillAppear

时间:2014-02-16 09:04:50

标签: ios ios7 uiviewcontroller

我正试图在ios7中获得新的viewController动画,但在尝试使用核心动画时遇到了路障。

我发现转换完成后,“查看”的控制器似乎没有接收到典型的视图生命周期方法,即viewWillAppearviewDidAppear。我称之为completeTransition:但这样做似乎足够了 - 这是典型的行为吗?或者我做错了什么?这是我的代码:

-(void)executeDismissalAnimation:(id<UIViewControllerContextTransitioning>)transitionContext{
UIView *inView = [transitionContext containerView];

UIViewController *toViewController      = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController *fromViewController    = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

toViewController.view.hidden = NO;

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    [fromViewController.view removeFromSuperview];
    [transitionContext completeTransition:YES];
}];

CGFloat duration = 0.4f;
CAKeyframeAnimation *scaleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.values = [self floatValuesFromValue:1.f toValue:1.5f withEasingFunction:ExponentialEaseInOut];
scaleAnimation.duration = duration;
scaleAnimation.fillMode = kCAFillModeForwards;
scaleAnimation.removedOnCompletion = YES;
[fromViewController.view.layer addAnimation:scaleAnimation forKey:nil];

CAKeyframeAnimation *alphaAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
alphaAnimation.values = [self floatValuesFromValue:1.f toValue:0.f withEasingFunction:LinearInterpolation];
alphaAnimation.duration = duration*2;
alphaAnimation.fillMode = kCAFillModeForwards;
alphaAnimation.removedOnCompletion = YES;
[fromViewController.view.layer addAnimation:alphaAnimation forKey:nil];

CAKeyframeAnimation *scaleAnimationB = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimationB.values = [self floatValuesFromValue:0.6f toValue:1.0f withEasingFunction:ExponentialEaseInOut];
scaleAnimationB.duration = duration;
scaleAnimationB.beginTime = CACurrentMediaTime()+0.3;
scaleAnimationB.fillMode = kCAFillModeForwards;
scaleAnimationB.removedOnCompletion = NO;
[toViewController.view.layer addAnimation:scaleAnimationB forKey:nil];

CAKeyframeAnimation *alphaAnimationB = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
alphaAnimationB.values = [self floatValuesFromValue:0.5f toValue:1.f withEasingFunction:LinearInterpolation];
alphaAnimationB.duration = duration;
alphaAnimationB.beginTime = CACurrentMediaTime()+0.3;
alphaAnimationB.fillMode = kCAFillModeForwards;
alphaAnimationB.removedOnCompletion = NO;
[toViewController.view.layer addAnimation:alphaAnimationB forKey:nil];

[CATransaction commit];

}

0 个答案:

没有答案
相关问题