子内容视图控制器视图的故事板的边界大小错误? [英] Child content view controller view has wrong bounds size from Storyboard?

查看:79
本文介绍了子内容视图控制器视图的故事板的边界大小错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此示例故事板上的文档大纲显示了我的工作.

我有一个自定义容器视图控制器和两个通过嵌入脚本连接的内容视图控制器.

这是情节提要本身.

ZetaViewController必须创建一些编程视图(当然是在ZetaView内).我注意到,当我将这些以编程方式创建的视图居中时,它们似乎确实偏离中心了.

ZetViewController通过检查 self.view.bounds.size.height self.view.bounds.size.width 并进行一些适当的算术来使事情居中.

当我向ZetaViewController添加调试日志记录时,我注意到 self.view.bounds.size.height self.view.bounds.size.width 的尺寸相等到ContainerView(768 x 1004)和 not ZetaView(728 x 637). IB中的大小检查器会确认这些值.

我为ZetaView的tag属性创建了一个与众不同的值并将其记录下来. ZetaViewController.view 确实是ZetaView,因为标签值可以确认.

那是怎么回事?为什么ZetaView在情节提要板上和大小"检查器中以较小的尺寸清晰显示,但在运行时在其属性中显示了错误的值?

解决方案

好的,我要指出的是我发现的一篇很棒的文章:(更新) http://kevindew.me /post/18579273258/在哪里可以在ios-5-和

中进行编程布局

在自动布局完成其神奇功能后,我在视图中添加阴影层的时间很糟糕. viewDidLoad,viewWillLoad等没有正确布局所有内容.

viewWillLayoutSubviews被调用了好几次,并且状态尚未完全设置.但是...在viewDidLayoutSubviews中,终于一切都按照我的预期进行了设置.

This document outline from my sample Storyboard shows what I'm working with.

I have a custom container view controller and two content view controllers connected via embed segues.

Here is the storyboard itself.

ZetaViewController has to create some programmatic views (within ZetaView, of course). I noticed when I was centering these programmatically created views they seemed really off center.

ZetViewController is centering things by examining self.view.bounds.size.height and self.view.bounds.size.width and doing some appropriate arithmetic.

When I added debug logging to ZetaViewController, I noticed that self.view.bounds.size.height and self.view.bounds.size.width had dimensions equal to ContainerView (768 x 1004) and not ZetaView (728 x 637). The Size Inspector in IB confirms these values.

I created a distinctive value for the tag attribute of ZetaView and logged it. ZetaViewController.view really is ZetaView because the tag value confirms it.

So what is going on? Why would ZetaView, shown clearly with smaller dimensions on the Storyboard and in the Size Inspector, show the wrong values in it's properties during run time?

解决方案

Ok,I'm going to point to an excellent post that I found: (updated) http://kevindew.me/post/18579273258/where-to-progmatically-lay-out-views-in-ios-5-and

I was having an awful time adding shadow calayers to views after autolayout had done its magic. viewDidLoad, viewWillLoad etc did not have everything correctly laid out.

viewWillLayoutSubviews is called quite a few times and the state isn't fully set up. However... In viewDidLayoutSubviews, finally everything was set up as I expected.

这篇关于子内容视图控制器视图的故事板的边界大小错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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