动画的presenting视图在UI presentationController [英] Animating the presenting view in a UIPresentationController

查看:237
本文介绍了动画的presenting视图在UI presentationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一些情况下,我建议你阅读这一点:

For some context, I recommend reading this:

非常相关的问题:<一href=\"http://stackoverflow.com/questions/24338700/from-view-controller-disappears-using-uiviewcontrollercontexttransitioning\">"From视图控制器&QUOT;消失使用UIViewControllerContextTransitioning
非常相关答案: http://stackoverflow.com/a/25901154/751268

我想实现一个动画新视图控制器覆盖半个屏幕的自定义视图控制器过渡,同时缩小了presenting视图控制器到90%(在窗口为本,$ P $下方psented视图控制器)。

I'm trying to implement a custom view controller transition that animates the new view controller to cover half the screen, while simultaneously shrinking the presenting view controller to 90% (centered in the window, underneath the presented view controller).

首先,我的问题是, viewFromKey:返回。为了解决这个问题,提到了答案:

First, my problem was that viewFromKey: returned nil. To solve that, the answer mentioned:

如果你想动画presenting视图控制器的观点,你应该考虑使用 UIModal presentationFullscreen 风格或继续使用 UIModal presentationCustom 和实现自己的 UI presentationController shouldRemove presentersView 返回YES。

If you want to animate the presenting view controllers's view you should consider using UIModalPresentationFullscreen style or continue using UIModalPresentationCustom and implement your own subclass of UIPresentationController with shouldRemovePresentersView returning YES.

我这样做,和 viewFromKey:不返回了,但现在的presenting视图控制器完全消失(这是有道理的考虑我明确地说,它应该通过实施 shouldRemove presentersView )。

I did that, and viewFromKey: doesn't return nil anymore, but now the presenting view controller disappears completely (which makes sense considering I explicitly say it should by implementing shouldRemovePresentersView).

我的presenting视图控制器的视图添加到容器视图,但它仍然被删除。还有什么我应该怎样做才能得到这个工作?

I add the presenting view controller's view to the container view, but it still gets removed. Is there anything else I should be doing to get this working?

下面是一些有关code:

Here's some relevant code:

UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey
UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];

BOOL show = self.isPresentation;
UIView *menuView = show ? toView : fromView;
UIView *backView = show ? fromView : toView;

UIView *containerView = [transitionContext containerView];

[containerView addSubview:backView];
[containerView addSubview:dimmedView];
[containerView addSubview:menuView];

// Adjust transforms, alpha and perform animations

我认为,通过返回 shouldRemove presentersView 并手动将它添加到 containerView ,应该解决这个问题,但 backView 反正被删除...

I thought that by returning YES from shouldRemovePresentersView and manually adding it to the containerView, that should fix the issue, but backView gets removed anyway...

推荐答案

我添加另一个答案,因为我的回答是太长了评论。

I'm adding another answer, as my response is too long to fit in a comment.

首先所有的 viewForKey 是iOS8上可用,所以除非你的目标iOS8上唯一的(为什么?)你不应该使用它,或检查后再使用该 UIViewControllerContextTransitioning 响应该选择并使用 viewControllerForKey 为iOS7。

First of all the viewForKey is available in iOS8, so unless you are targeting iOS8 only (why?) you should not use it, or use it after checking that the UIViewControllerContextTransitioning responds to that selector and use the viewControllerForKey for iOS7.

有了这样说,在我看来,这是一个错误,我解释一下我自己:

With that being said, it seems to me that this is a bug and I explain my self:

如果你看看 UI presentationController 头文件,你会看到,它说:

If you look at the UIPresentationController header file, you will see that it says

// Indicate whether the view controller's view we are transitioning from will be removed from the window in the end of the
// presentation transition
// (Default: YES)
- (BOOL)shouldRemovePresentersView;

所以你看到的默认值是YES,所以当你特别想说NO这应该只覆盖。
但是,你是对的,而这一点没有明确设置为YES时, viewForKey UITransitionContextFromViewControllerKey 仍然为零。

我想你应该在bug报告填补了这一点,现在使用 viewControllerForKey 这是很好的被使用(没有错),因为它不是去precated并没有问题,在这两个操作系统版本的作品。

I think you should fill in a bug report for this and for now use the viewControllerForKey which is fine to be used (nothing wrong with this) as it's not deprecated and works in both OS versions without a problem.

这是最有可能的原因的错误是, viewForKey 应返回的视图 UITransitionContextFromViewControllerKey < STRONG>在的 shouldRemove presentersView 明确设置为而非

And the reason this is most likely a bug is that the viewForKey should return a view for theUITransitionContextFromViewControllerKey when the shouldRemovePresentersView is explicitly set to NO and not YES.

我的2美分

这篇关于动画的presenting视图在UI presentationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆