【发布时间】:2018-10-11 15:03:01
【问题描述】:
我有一个图像数组的滚动视图,它适用于图像左右滚动,但我不能向下滚动,而是能够滚动我的表格视图单元格...我需要能够向下滚动并且我的图像数组没有固定在视图上,有什么办法吗?
我使用的代码是:
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 { 让单元格:MainMenuRowSelectionTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! 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
}
还有我的故事板
这样,我的滚动视图根本不会出现
【问题讨论】:
-
您可以使用 UICollectionView 以 Grid 格式显示图像,而不是使用 UIScrollView。它将解决滚动问题,并再次以更简单的方式实现您期望的功能。
标签: ios swift uiscrollview