ios - 在 iOS 7 中,随着客户 VC 转换,是否可以在 presentViewController 之后在屏幕上显示 "fromviewcontroller"?

标签 ios ios7 presentviewcontroller custom-transition

许多应用程序都具有这样的功能,即用户可以下拉一个 View ,然后从下方显示另一个 View 。但是第一个 View 在底部仍然可见。 (例如 Facebook Paper App)。

如果另一个 View 来自另一个 View Controller ,是否可以通过使用 iOS 7 的自定义 View Controller 转换 API 来实现?

在我的测试中,可以执行“呈现”部分,但“解散”部分出现故障。每当我们调用 dismissViewController 时,“toViewController”甚至在调用 transitioningDelegate 方法之前就接管了整个屏幕。

有没有人比较熟悉这个?谢谢!

最佳答案

If the other view is from another view controller, is it possible to achieve this by using iOS 7's custom view controller transitioning API ?

是的,这是可能的。您可以使用快照 API 拍摄任何 UIView 的快照。有了它,您可以拍摄要转换的 View Controller 的快照,然后将其添加到要转换到的 View Controller 下方的 containerView

例如,在采用 UIViewControllerAnimatedTransitioning 的类的 -animateTransition: 方法中,拍摄要转换的 View Controller 的快照并将其添加为 subview 在您要转换到的 View Controller 下方:

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {

    UIView * containerView = transitionContext.containerView;
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    // take snapshot of from view controller
    UIView * fromSnapshotView = [fromViewController.view snapshotViewAfterScreenUpdates:NO];
    [containerView insertSubview:fromSnapshotView belowSubview:toViewController.view];

    // Then do your animations on the to view controller to animate it into view as well as the fromSnapshotView

    // Finally, don't forget to call:
    [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}

In my test, it is possible to do the "presenting" part, but the "dismissing" part has a glitch. Whenever we call dismissViewController, the "toViewController" takes over the full screen even before calling the transitioningDelegate methods.

如果您对 dismiss 的调用没有触发您的过渡委托(delegate)方法,请确保在 dismiss 之前在该 View Controller 上设置过渡委托(delegate)。

关于ios - 在 iOS 7 中,随着客户 VC 转换,是否可以在 presentViewController 之后在屏幕上显示 "fromviewcontroller"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22617368/

相关文章:

html - iOS 7 doesn't show more than one line when option is longer than screen size

ios - AVAssetExportSession - 在 IOS 中加入 2 个 mp4 文件

ios - 如何向添加到 tableview 单元格的减号图像添加可访问性标签?

ios7 - 如何检查按钮形状设置是否启用?

ios7 - 多人连接断开

uinavigationcontroller - iOS Swift 中的 navigationController!.pushViewController 与 PresentViewController

ios - 关闭堆栈中较低的 ViewController 并不像预期的那样表现

ios - 动画 View Controller 并同时在 TableView 中重新加载数据

ios - "Cannot assign image to *UIImageView*"SWIFT 错误(iOS)

ios - NSSet SetByArray 混淆了为什么我有一个额外的元素 - SKProductsRequest 无法正常工作