我正在使用新的UINavigationController 7自定义转换API重新创建iOS Push动画。
animationControllerForOperation把视图推得很好UIPercentDrivenInteractiveTransition子类和来自WWDC 2013 218 -使用视图控制器的自定义转换的集成代码。1. Interactive pop starts
2. Finger is lifted after a short distance - red screenshot
3. The view animates back a short distance.
4. Red view is removed (I think) - black screenshot.


完整的代码在GitHub上,但是这里有两个部分我想是很重要的。
- (void)didSwipeBack:(UIScreenEdgePanGestureRecognizer *)edgePanGestureRecognizer {
if (state == UIGestureRecognizerStateBegan) {
self.isInteractive = YES;
[self.parentNavigationController popViewControllerAnimated:YES];
}
if (!self.isInteractive) return;
switch (state)
{
case UIGestureRecognizerStateChanged: {
// Calculate percentage ...
[self updateInteractiveTransition:percentagePanned];
break;
}
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateEnded: {
if (state != UIGestureRecognizerStateCancelled &&
isPannedMoreThanHalfWay) {
[self finishInteractiveTransition];
} else {
[self cancelInteractiveTransition];
}
self.isInteractive = NO;
break;
}
}
}UIViewControllerAnimatedTransitioning协议
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
// Grab views ...
[[transitionContext containerView] addSubview:toViewController.view];
// Calculate initial and final frames
toViewController.view.frame = initalToViewControllerFrame;
fromViewController.view.frame = initialFromViewControllerFrame;
[UIView animateWithDuration:RSTransitionVendorAnimationDuration delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
toViewController.view.frame = finalToViewControllerFrame;
fromViewController.view.frame = finalFromViewControllerFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}有人知道为什么屏幕是空白的吗?或者谁能给我指一些样本代码。苹果似乎没有任何使用百分比驱动的交互转换的示例代码。
发布于 2014-04-01 21:03:41
第一个问题是我复制的Apple示例代码中的一个bug。completeTransition方法应该有一个更智能的BOOL参数,如下所示:
[UIView animateWithDuration:RSTransitionVendorAnimationDuration delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
toViewController.view.frame = finalToViewControllerFrame;
fromViewController.view.frame = finalFromViewControllerFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];感谢@rounak为我指点objc.io邮政。
这就提出了另一个与动画有关的问题。动画会停下来,呈现一个空白的视图,然后继续进行。这几乎是一个公然的UIKit错误。修复方法是将completionSpeed设置为0.99而不是1.0。默认值是1.0,所以我想,将其设置为1.0不会在他们的自定义setter中产生一些副作用。
// self is a UIPercentDrivenInteractiveTransition
self.completionSpeed = 0.99;发布于 2014-03-31 21:15:41
我不认为您需要一个UIPercentDrivenInteractiveTransition子类。我只需创建一个新的UIPercentDrivenInteractiveTransition对象,保存对它的强引用并在interactionControllerForAnimationController方法中返回它。
此链接用于交互式过渡。非常有用。
https://stackoverflow.com/questions/22770779
复制相似问题