ios - 在 Swift 中嵌套 UIScrollView
问题描述
我有一个图像数组的滚动视图,它适用于图像左右滚动,但我无法向下滚动,而是能够滚动我的表格视图单元格......我需要能够向下滚动并且没有我的固定在视图上的图像数组,有什么办法吗?
我使用的代码是:
override func viewDidLoad() {
super.viewDidLoad()
scrollView.frame = view.frame
imageArray = [UIImage(named:"adsImage3")!,UIImage(named:"adsImage2")!,UIImage(named:"adsImage")!]
navigationController?.navigationBar.barTintColor = UIColor.white
for i in 0..<imageArray.count {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
imageView.image = imageArray[i]
let xPosition = self.view.frame.width * CGFloat(i)
imageView.frame = CGRect(x: xPosition, y: 0, width: self.scrollView.frame.width, height: 380)
scrollView.contentSize.width = scrollView.frame.width * CGFloat(i + 1)
scrollView.addSubview(imageView)
}
}
如果我将滚动视图放在我的表格视图中,我的代码将是 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: MainMenuRowSelectionTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for : indexPath) 一样!MainMenuRowSelectionTableViewCell
var cellColors = ["#FFB3B3","#FFFFFF"]
cell.contentView.backgroundColor = UIColor(hexString: cellColors[indexPath.row % cellColors.count])
imageArray = [UIImage(named:"adsImage3")!,UIImage(named:"adsImage2")!,UIImage(named:"adsImage")!]
for i in 0..<imageArray.count {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
imageView.image = imageArray[i]
}
return cell
}
和我的故事板
这样,我的滚动视图根本不会出现
解决方案
我需要能够向下滚动并且不将我的图像数组固定在视图上
表格视图是垂直滚动视图。您应该将图像的水平滚动视图转换为表格视图(即它的tableHeaderView
)的标题视图,并使表格视图占据整个屏幕。现在您可以滚动表格,并将图像的滚动视图向上滚动到屏幕之外。
推荐阅读
- javascript - 下拉自动选择禁用
- lets-encrypt - Indescript LetsEncript 证书生成错误
- visual-studio-2017 - 为什么 Visual Studio 2017 无法为 Swagger Petstore 生成 REST API 客户端?
- css - 元素后仅适用于跨度
- python - Python Scrape of table 不返回数据
- excel - 从 VBA Excel 打开和关闭 Word 文档
- regex - 从数字列表创建范围
- javascript - JavaScript:一个画布多个纹理
- hive - 在 Hive 中获取日期周(周开始)
- php - 连接、查询和同时使用 2 个或更多数据库