Ios 为什么我的图层蒙版在[cancelInteractiveTransition]和animationDidStop:之间重置为(0,0,0,0)?
我们的应用程序的交互转换中存在一个闪烁问题,即在iOS 8上使用Ios 为什么我的图层蒙版在[cancelInteractiveTransition]和animationDidStop:之间重置为(0,0,0,0)?,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我们的应用程序的交互转换中存在一个闪烁问题,即在iOS 8上使用UIPercentDrivenInteractiveTransition。这似乎是因为to层的遮罩被重置(到第0帧),导致to视图被显示,即使转换被取消。。。我不知道为什么 以下是动画代码: - (UIView *)fromView { UIViewController *fromVC = [self.transitionContext viewControllerForKey:UITransitionContextFrom
UIPercentDrivenInteractiveTransition
。这似乎是因为to层的遮罩被重置(到第0帧),导致to视图被显示,即使转换被取消。。。我不知道为什么
以下是动画代码:
- (UIView *)fromView {
UIViewController *fromVC = [self.transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
BOOL hasViewForKey = [self.transitionContext respondsToSelector:@selector(viewForKey:)]; // viewForKey is iOS8+.
UIView *fromView = hasViewForKey ? [self.transitionContext viewForKey:UITransitionContextFromViewKey] : fromVC.view;
return fromView;
}
- (UIView *)toView {
UIViewController *toVC = [self.transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
BOOL hasViewForKey = [self.transitionContext respondsToSelector:@selector(viewForKey:)]; // viewForKey is iOS8+.
UIView *toView = hasViewForKey ? [self.transitionContext viewForKey:UITransitionContextToViewKey] : toVC.view;
return toView;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
self.transitionContext = transitionContext;
// The container view, which, according to the docs, “acts as the superview for the views involved in the transition.”
UIView *containerView = [transitionContext containerView];
// The from view controller, to view controller, and final frame for the to view controller’s view are all
// extracted from the transition context. The final frame has to be set to avoid flickering
UIView *fromView = [self fromView];
UIView *toView = [self toView];
switch (self.operation) {
case UINavigationControllerOperationPush: {
self.viewBeingMasked = toView;
[containerView addSubview:toView];
break;
}
case UINavigationControllerOperationPop: {
self.viewBeingMasked = fromView;
[containerView insertSubview:toView belowSubview:fromView];
break;
}
default:
break;
}
// Create bezier paths used for animations start, middle and end:
CGRect fromFrame = fromView.frame;
CGRect maskingRect = CGRectMake(0, 0, fromFrame.size.width * kScaleFactor, fromFrame.size.height * kScaleFactor);
UIBezierPath *startPath = [UIBezierPath bezierPathWithRect:maskingRect];
CGAffineTransform transform = [self affineTransformToMoveMaskingRectToX:fromFrame.size.width y:(fromFrame.size.height * self.switcherHandlePosition)andHeight:self.switcherHandleHeight];
[startPath applyTransform:transform];
[startPath applyTransform:CGAffineTransformMakeTranslation(-self.switcherHandleHeight, 0)];
UIBezierPath *middlePath = [startPath copy];
CGAffineTransform horizontalTransform = CGAffineTransformMakeTranslation(-(fromFrame.size.width / 2 - self.switcherHandleHeight), 0);
[middlePath applyTransform:horizontalTransform];
UIBezierPath *endPath = [UIBezierPath bezierPathWithRect:maskingRect];
[endPath applyTransform:CGAffineTransformMakeTranslation(kMaskingRectXPositionEnd, 0)];
// other direction when popping
if (self.operation == UINavigationControllerOperationPop) {
UIBezierPath *tmp = startPath;
startPath = endPath;
endPath = tmp;
}
// Creates a new CAShapeLayer to represent the mask. You assign its path value with the final path after the animation
// to avoid the layer snapping back after the animation completes...
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.path = endPath.CGPath;
self.viewBeingMasked.layer.mask = maskLayer;
CAKeyframeAnimation *maskAnimation;
maskAnimation = [self maskAnimationWithEndPath:endPath middlePath:middlePath startPath:startPath transitionContext:transitionContext];
maskAnimation.removedOnCompletion = NO;
[maskLayer addAnimation:maskAnimation forKey:@"path"];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
// BREAKPOINT 1 HERE
if( self.transitionContext.transitionWasCancelled ) {
NSAssert(self.viewBeingMasked == [self toView], @"TESTING");
[[self toView] removeFromSuperview];
[[self.transitionContext containerView] addSubview:[self fromView]];
}
[self.transitionContext completeTransition:!self.transitionContext.transitionWasCancelled];
self.viewBeingMasked.layer.mask = nil;
}
发生的情况是,在finishInteractiveTransition
和cancelInteractiveTransition
之间的某个地方,掩码被重置:如果我在“断点1”处中断,我会看到self.viewBeingMasked.layer.mask
存在,但有帧(0,0,0)。我希望它有一个表示端点的帧(CGPath endPath)
是什么杀死了我的面具?我该如何修复?谢谢你的帮助
case UIGestureRecognizerStateEnded:
if ([self completionProgress:gestureRecognizer] >= 0.5) {
[self.interactionController finishInteractiveTransition];
} else {
[self.interactionController cancelInteractiveTransition];
}