【发布时间】:2014-05-11 08:03:01
【问题描述】:
我正在使用新的 iOS 7 自定义转换 API 重新创建 UINavigationController Push 动画。
- 我使用
animationControllerForOperation可以很好地推送和弹出视图 - 我为交互式弹出手势添加了边缘手势识别器。
- 我使用了
UIPercentDrivenInteractiveTransition子类和来自WWDC 2013 218 - Custom Transitions Using View Controllers 的集成代码 - 好像是误删了fromViewController,不知道为什么。
-
步骤如下:
- 交互式流行音乐开始
- 短距离后抬起手指 - 红色截图
- 视图动画返回一小段距离。
- 红色视图被移除(我认为) - 黑色屏幕截图。
The full code is on GitHub,但这里有两部分我认为很重要。
Gesture delegate
- (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 protocol
- (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];
}];
}
有人知道为什么屏幕是空白的吗?或者任何人都可以指出一些示例代码。 Apple 似乎没有任何使用百分比驱动交互的交互过渡示例代码。
【问题讨论】:
-
为什么你现在弹出视图控制器
UIGestureRecognizerStateBegan而不是UIGestureRecognizerStateEnded? -
@ismailgulek 这就是交互式过渡的工作原理。
标签: ios cocoa-touch uiviewcontroller uinavigationcontroller core-animation