【发布时间】:2015-10-10 21:17:30
【问题描述】:
我正在构建一个视图控制器,其中包含一些 UIView 元素和一个 UITableView。这个视图将比 iPhone 屏幕大,比我将所有这些元素放在 UIScrollView 和配置的自动布局中。
UITableView 中的行数是动态的,我需要在单个屏幕中显示所有内容。我不想启用 UITableView 滚动属性,因为使用主 UIScrollView 和 UITableview 滚动会完全混乱
几天来我一直在 StackOverflow 上研究有关此问题的帖子,但找不到与我的问题类似的内容。
这是尝试调整 UITableView 和 UIScrollView 大小的代码
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Configuring dataSource an delegate
self.tableView.dataSource = self
self.tableView.delegate = self
// Sizing all the elements inside scrollView
var contentRect = CGRectZero
for view:UIView in self.scrollView.subviews {
contentRect = CGRectUnion(contentRect, view.frame)
}
print(contentRect)
// Trying to resize the tableView and scrollView to fit more contents
self.tableView.contentSize = CGSizeMake(scrollView.frame.width, CGFloat(441))
scrollView.contentSize = CGSizeMake(scrollView.frame.width, CGFloat(877))
scrollView.delaysContentTouches = true
scrollView.canCancelContentTouches = false
// Looking for a new size and nothing change
var contentRect2 = CGRectZero
for view:UIView in self.scrollView.subviews {
contentRect2 = CGRectUnion(contentRect2, view.frame)
}
print(contentRect2)
print("Tableview width \(self.tableView.frame.width)")
print("Tableview height \(self.tableView.frame.height)")
}
GitHub上的示例项目
感谢您的帮助
ViewControl的布局:
【问题讨论】:
标签: ios swift uitableview uiscrollview resize