ios - 在 viewDidLoad IOS 10 中获取内部 View 大小

标签 ios xcode uitableview uiviewcontroller

我针对我的问题制作了一个演示项目。我在 UIViewController 中添加了一个 TableView 。我像这张图片一样设置了 tableview 约束。当我想获得这个边界和框架时,我收到了图片 2。我如何获得 viewDidAppear 内部的 tableView 大小?

enter image description here

enter image description here

最佳答案

UIView 有一个 frame 属性,因为 UITableView 继承自 UIView,你可以只使用 tableView.frame 来获取它的框架,而要获取它的宽度和高度,你可以使用 tableView.frame.size.width 和 tableView.frame.size。高度。

请注意,您不会在 viewDidLoad 中获得正确的 View 尺寸,但您会在 viewWillAppear 和 viewDidAppear 中获得正确的宽度和高度。

如果你想要屏幕尺寸,你总是可以使用 UIScreen.mainScreen().bounds.height 和 UIScreen.mainScreen().bounds.width

希望这对您有所帮助。

关于ios - 在 viewDidLoad IOS 10 中获取内部 View 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39658911/

相关文章:

ios - 使用 RSBarcodes 扫描条形码时执行操作

ios - UICollectionView 在 insertSections 上崩溃,endItemAnimationsWithInvalidationContext :tentativelyForReordering:

ios - 试图让我的投票系统工作并在 Parse 中登录后端

ios - Xcode 6 和 iOS 8 更新后 UITableView 旋转表现奇怪

UITableView 在不使用编辑按钮的情况下启动行重新排列

ios - 如何更改 iOS "UITableView negative space"颜色?

ios - 如何在 Swift 中将绘图保存到 tableview 中?

ios - 如果使用 "ActiveLabel.swift"标记单词有空格,它将标记失败 - swift

objective-c - 不旋转标签栏 View Controller 中的仅一个 View

ios - 加载 View Controller ,但直到第二次点击 tableview 才出现