我有一个自定义UITableView
,其中包含无限的Scroll和Paging Enable。我的每个单元格在背景上都有UIImageView
,我希望每次向上或向下滚动它都会将每个图像显示为全屏。
我将此功能用于全屏,但在一次无限滚动后我的视图不是全屏。
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return self.view.frame.size.height
}
答案 0 :(得分:0)
请在下面找到源代码,您可以在其中滚动表格视图以及不同的图像。
Swift 4
//
// ImageTVC.swift
//
// Created by Test User on 06/02/18.
// Copyright © 2018. All rights reserved.
//
import UIKit
class ImageTVC: UITableViewCell {
@IBOutlet weak var imgView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
//
// TableViewVC.swift
//
// Created by Test User on 06/02/18.
// Copyright © 2018. All rights reserved.
//
class TableViewVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
extension TableViewVC: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}
//----------------------------------------------------------------
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ImageCell") as! ImageTVC
if indexPath.item % 2 == 0 {
cell.imgView?.backgroundColor = UIColor(red: CGFloat(indexPath.item * 2)/255.0, green: CGFloat(indexPath.item * 0)/255.0, blue: CGFloat(indexPath.item * 0)/255.0, alpha: 1.0)
} else if indexPath.item % 3 == 0 {
cell.imgView?.backgroundColor = UIColor(red: CGFloat(indexPath.item * 0)/255.0, green: CGFloat(indexPath.item * 2)/255.0, blue: CGFloat(indexPath.item * 0)/255.0, alpha: 1.0)
} else {
cell.imgView?.backgroundColor = UIColor(red: CGFloat(indexPath.item * 0)/255.0, green: CGFloat(indexPath.item * 0)/255.0, blue: CGFloat(indexPath.item * 2)/255.0, alpha: 1.0)
}
print("IndexPath.row = \(indexPath.row)")
return cell
}
//----------------------------------------------------------------
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return tableView.bounds.size.height
}
}
还可以找到故事板设计。
答案 1 :(得分:0)
最新答案,可能会对他人有所帮助。 用于TableViewcell的全屏分页。请执行以下步骤。
(考虑为不带导航栏)
按如下所示配置Tableview。
覆盖func viewDidLoad(){
super.viewDidLoad()
configureTableView()
}
私人功能configureTableView(){
tableView.rowHeight = UIScreen.main.bounds.height
tableView.estimatedRowHeight = UIScreen.main.bounds.height
tableView.separatorStyle = .none
tableView.isPagingEnabled = true
tableView.bounces = false
tableView.estimatedSectionHeaderHeight = CGFloat.leastNormalMagnitude
tableView.sectionHeaderHeight = CGFloat.leastNormalMagnitude
tableView.estimatedSectionFooterHeight = CGFloat.leastNormalMagnitude
tableView.sectionFooterHeight = CGFloat.leastNormalMagnitude
tableView.contentInsetAdjustmentBehavior = .never
tableView.delegate = self
tableView.dataSource = self
}