ios 8改变了呈现/模态视图控制器的大小 [英] ios 8 change the size of presented/modal view controller

查看:556
本文介绍了ios 8改变了呈现/模态视图控制器的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ios 7和之前,我正在更新presentViewController.view.superview的边界以自定义呈现的视图控制器的大小,但似乎在ios 8中不再是这种情况。由于没有superview可以在视图控制器上设置(当你尝试在调试器中调用它时返回nil)。

In ios 7 and before, I was updating the bounds of presentedViewController.view.superview to custom the size of presented view controller, but it seems this would not be the case in ios 8 any more. Since there is no superview can be set on the view controller(return nil when you try to call it in debugger).

如何更新显示的视图控制器的大小?这将用于自定义演示文稿转换。

Any suggestions how to update the presented view controller's size? This would be used for the custom presentation transition.

推荐答案

如果有人遇到此问题,请按以下方式解决。

In case anyone runs into this later, here is how I solve it.

UIPresentationController的子类,并在frameOfPresentedViewInContainerView中返回帧。将其输入您为presentViewController创建的transitioningDelegate。

Subclass the UIPresentationController and return the frame in frameOfPresentedViewInContainerView. Feed this into the transitioningDelegate that you create for the presentedViewController.

或者,您可以在animateTransition中设置presentView的最终帧:属于您为transitioningDelegate创建的动画对象。但是,这是iOS 7的旧方式。由于Apple引入了UIPresentationController,所以应该在那里进行任何大小/帧更改,这是我之前提到的方法。

Or, you may set the final frame for the presentedView in the animateTransition:, which belongs to the animator object you created for transitioningDelegate. However, this is the old iOS 7 way of doing it. Since Apple introduce UIPresentationController, any size/frame changes should be done there instead, which is the previous method I mentioned.

以下是一些可能与解决问题无直接关系的额外信息。

对于那些从未接触过苹果视图控制器转换api的人,就像我之前一样,这里是步骤。

For those of you who never got your hands on the apple view controller transition api, just like me before, here are the steps.


  1. 创建符合UIViewControllerTransitioningDelegate的YourTransitioningDelegate。在这里,通常需要设置三件事,PresentationController,PresentedAnimationController,DismissedAnimationController。

  1. Create YourTransitioningDelegate, which conforms UIViewControllerTransitioningDelegate. In here, generally three things need to be set, PresentationController, PresentedAnimationController, DismissedAnimationController.

创建符合UIViewControllerAnimatedTransitioning的YourTransitionAnimator。这里需要覆盖两个函数,transitionDuration和animateTransition(这是所有动画发生的地方,添加/删除和动画显示的视图。让你在transitionContext上调用completeTransition来结束动画)。

Create YourTransitionAnimator, which conforms UIViewControllerAnimatedTransitioning. Here, two functions need to be override, transitionDuration and animateTransition(This is where all the animation happens, adding/removing and animating the presentedView. Make you call completeTransition on transitionContext to end the animation).

子类UIPresentationController。取决于每个人的需求,你可以在这里做很多事情。我刚刚添加了dimmingView并更改了presentViewController的框架。

Subclass UIPresentationController. Depends on each individual needs, you may do a ton of things here. I just added a dimmingView and changed the frame of presentedViewController.

最后,在呈现视图控制器之前解决问题,即将modalPresentationStyle更改为自定义并设置转换委托。

Finally, hook things up before presenting the view controller, which is changing the modalPresentationStyle to be custom and setting the transitioning delegate.

我发现真正有用的东西,两个2014年WWDC视频(查看控制器进步和一看内部演示控制器)和来自的示例项目苹果(LookInside-photoEditingApp)。

Things I found really helpful, two 2014 WWDC videos("View controllers advancements" and "A look inside presentation controllers") and the sample project from Apple(LookInside-photoEditingApp).

这篇关于ios 8改变了呈现/模态视图控制器的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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