gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 10:45:19 25 4
gpt4 key购买 nike

许多应用程序都具有这样的功能,即用户可以下拉一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com