我正在实现自定义导航过渡,并使用UIPercentDrivenInteractiveTransition来完成这一操作.
我有非交互过渡工作正常,我正在使用动画块来处理过渡动画,但是一旦我在交互式过渡中添加,如果我取消过渡,屏幕现在变黑.
这是我跟踪手势的代码:
-(void)userDidPan:(UIScreenEdgePanGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:nil];
if (recognizer.state == UIGestureRecognizerStateBegan) {
// We're being invoked via a gesture recognizer – we are necessarily interactive
self.hasActiveInteraction = YES;
self.interactiveTransition = [BXTPercentDrivenInteractiveTransition new];
[[BXTNavigationController sharedNavigationController] popViewControllerAnimated:YES];
}
else if (recognizer.state == UIGestureRecognizerStateChanged) {
CGFloat ratio = location.x / CGRectGetWidth(recognizer.view.frame);
NSLog(@"Percentage complete: %0.2f",ratio*100);
[self.interactiveTransition updateInteractiveTransition:ratio];
}
else if (recognizer.state == UIGestureRecognizerStateEnded) {
// Depending on our state and the velocity, determine whether to cancel or complete the transition.
CGFloat ratio = location.x / CGRectGetWidth(recognizer.view.frame);
if (ratio > 0.50) {
NSLog(@"Completing");
[self.interactiveTransition finishInteractiveTransition];
}
else {
NSLog(@"Canceling");
[self.interactiveTransition cancelInteractiveTransition];
}
}
}
…当弹出视图控制器时,这是一个(缩写)查看我的动画块:
[UIView animateWithDuration:kBXTNavigationTimingDuration
delay:0
options:animationOption
animations:^{
toVC.view.frame = destinationFrameForPoppedView;
fromVC.view.frame = CGRectOffset(fromVC.view.frame, fromVC.view.frame.size.width, 0);
} completion:^(BOOL finished) {
[darkeningView removeFromSuperview];
[_transition.secondaryTransitionViews enumerateObjectsUsingBlock:^(BXTTransitionView *transitionView, NSUInteger idx, BOOL *stop) {
[transitionView.view removeFromSuperview];
}];
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
在使用自定义导航过渡取消左侧滑动动画时,为什么屏幕会变黑?
最佳答案 解决了!我删除了动画完成块中的所有removeFromSuperview调用,它解决了它(我遇到了和你一样的问题,几乎相同的代码,请看我对你的评论’).尝试从代码中删除这些行:
[darkeningView removeFromSuperview];
[_transition.secondaryTransitionViews enumerateObjectsUsingBlock:^(BXTTransitionView *transitionView, NSUInteger idx, BOOL *stop) {
[transitionView.view removeFromSuperview];
}];