需要更多关于援助viewDidLayoutSubviews [英] Need assistance regarding viewDidLayoutSubviews

查看:171
本文介绍了需要更多关于援助viewDidLayoutSubviews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

苹果关于文档 viewDidLayoutSubviews 说:

在边界的视图控制器的看法改变,视图
  调整其子视图的位置,然后系统会调用此
  方法。但是,的被调用此方法不指示
  该视图的子视图的各个布局进行了调整。
每个
  子视图负责调整自己的布局。

When the bounds change for a view controller's view, the view adjusts the positions of its subviews and then the system calls this method. However, this method being called does not indicate that the individual layouts of the view's subviews have been adjusted. Each subview is responsible for adjusting its own layout.

您的视图控制器可以重写此方法进行修改视图勾画出它的子视图后。默认的这个实施
  方法不起作用。

Your view controller can override this method to make changes after the view lays out its subviews. The default implementation of this method does nothing.

厂景包含视图2 办法视图2 厂景 A子视图。我创建一个的CALayer 我的视图2 我想成为视图2的确切大小。我使用自动布局所以我想创建的CALayer 自动布局完成其工作,以便我能有正确的价值观,为的CALayer 框架集。

I have view1 which contains view2 means view2 is a subview of view1. I am creating a CALayer for my view2 which I want to be exact size of view2. I am using auto layouts so I want to create the CALayer when auto layout finish its work so I can have correct values to set for CALayer frame.

viewDidLayoutSubviews 方法时,正好视图2 帧由自动布局因为苹果的文档也说,

But in viewDidLayoutSubviews method I can't detect when exactly view2 frame is set by auto layout because Apple doc is also saying that

此方法被称为不表示各个
  该视图的子视图的布局进行了调整。

this method being called does not indicate that the individual layouts of the view's subviews have been adjusted.

之后,苹果的文档说

您的视图控制器可以重写此方法后,做出改变
  视图勾画出它的子视图。

Your view controller can override this method to make changes after the view lays out its subviews.

我很困惑在什么点自动布局将设置视图2 框架,所以我可以把我的的CALayer 帧相应。

I am so confused at what point auto layout will set view2 frame so I can set my CALayer frame accordingly.

推荐答案

正如我在评论中提到,你没有,如果你的观点是自动对齐布局做什么特别的事情。如果你想有一个单层来调整它的边界到视图的边界,最简单,最正确的方法将覆盖 layerClass 视图的方法 - 在这种情况下,层边界会自动在视图中调整。如果你除了标准的一,更新层的边界可能是最好的地方,需要一个或多个层 SETFRAME:方法重写

As I mentioned in the comments, you don't have to do anything special if your view is aligned with auto layout. If you want a single layer to adjust it's bounds to the view's bounds, the most simple and correct way will be overriding layerClass method of the view - in that case layer bounds will be adjusted within a view automatically. If you need one more layer in addition to the standard one, the best place to update layer's bounds may be setFrame: method override.

由于 viewDidLayoutSubviews 的,它只是告诉你,这的ViewController的根视图的子视图都定位在希望的地方的事件。你不能保证所有这些子视图的其余子视图也将对准,因为它是父视图自身的责任。他们既可以是自动布局定位和手动定位的布局。此事件也不能保证所有的视图中显示为所需的,特别是如果它们的帧变化是动画

As of viewDidLayoutSubviews, it is just an event to inform you, that all subviews of viewcontroller's root view are positioned at the desired places. You are not guaranteed that all the rest subviews of those subviews will also be aligned, since it is a responsibility of the parent view itself. they can be both auto layout positioned and manual layout positioned. This event also does not guarantee that all the the views are displayed as desired, especially if their frame change is animated.

这篇关于需要更多关于援助viewDidLayoutSubviews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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