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

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

问题描述

在 ios 7 及之前,我更新了presentedViewController.view.superview 的边界以自定义呈现的视图控制器的大小,但在ios 8 中似乎不再是这种情况.由于没有可以在视图控制器上设置超级视图(当您尝试在调试器中调用它时返回 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 中返回框架.将此输入到您为presentedViewController 创建的transitioningDelegate 中.

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

或者,您可以在 animateTransition: 中为presentedView 设置最后一帧,它属于您为transitioningDelegate 创建的animator 对象.但是,这是旧的 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并更改了presentedViewController的框架.

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 视频(查看控制器的进步"和演示控制器内部的外观")和来自 Apple 的示例项目(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天全站免登陆