我尝试使用过渡动画显示侧边栏,但是如果在通话或定位过程中出现蓝色状态栏,则该应用程序将返回到后台,然后转到前台,该页面将显示异常。
我尝试在UIApplicationDidEnterBackgroundNotification时关闭侧边栏,而在UIApplicationWillEnterForegroundNotification时打开侧边栏,但是不起作用。
- (void)defaultAnimationWithContext:(id <UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
CWMaskView *maskView = [CWMaskView shareInstance];
maskView.frame = fromVC.view.bounds;
[fromVC.view addSubview:maskView];
UIView *containerView = [transitionContext containerView];
UIImageView *imageV;
if (self.configuration.backImage) {
imageV = [[UIImageView alloc] initWithFrame:containerView.bounds];
imageV.image = self.configuration.backImage;
imageV.transform = CGAffineTransformMakeScale(1.4, 1.4);
imageV.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
}
[containerView addSubview:imageV];
CGFloat width = self.configuration.distance;
CGFloat x = - width / 2;
CGFloat ret = 1;
if (self.configuration.direction == CWDrawerTransitionFromRight) {
x = kCWSCREENWIDTH - width / 2;
ret = -1;
}
toVC.view.frame = CGRectMake(x, 0, CGRectGetWidth(containerView.frame), CGRectGetHeight(containerView.frame));
[containerView addSubview:toVC.view];
[containerView addSubview:fromVC.view];
CGFloat translationX = width - (kCWSCREENWIDTH * (1 - self.configuration.scaleY) / 2);
CGAffineTransform t1 = CGAffineTransformMakeScale(self.configuration.scaleY, self.configuration.scaleY);
CGAffineTransform t2 = CGAffineTransformMakeTranslation(ret * translationX, 0);
CGAffineTransform fromVCTransform = CGAffineTransformConcat(t1, t2);
CGAffineTransform toVCTransform;
if (self.configuration.direction == CWDrawerTransitionFromRight) {
toVCTransform = CGAffineTransformMakeTranslation(ret * (x - CGRectGetWidth(containerView.frame) + width), 0);
}else {
toVCTransform = CGAffineTransformMakeTranslation(ret * width / 2, 0);
}
[UIView animateKeyframesWithDuration:[self transitionDuration:transitionContext] delay:0 options:0 animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:1.0 animations:^{
fromVC.view.transform = fromVCTransform;
toVC.view.transform = toVCTransform;
imageV.transform = CGAffineTransformIdentity;
maskView.alpha = self.configuration.maskAlpha;
}];
} completion:^(BOOL finished) {
if (![transitionContext transitionWasCancelled]) {
maskView.userInteractionEnabled = YES;
[transitionContext completeTransition:YES];
[containerView addSubview:fromVC.view];
}else {
[imageV removeFromSuperview];
[CWMaskView releaseInstance];
[transitionContext completeTransition:NO];
}
}];
}