在我的应用程序中,我在表视图上使用了视差效果。因此,我使用UIEdgeInsets来显示效果。这是不带节的完美工作,但是当我尝试使用节时,它看起来很丑,并且在上下滚动时,节变得僵硬。我附上了夹子,以留出更多空间。而且我使用波纹管代码。 link请帮助我
override func viewDidLoad()
{
super.viewDidLoad()
tblItemList.contentInset = UIEdgeInsets(top: 200, left: 0, bottom: 0, right: 0)
imageView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 200)
imageView.image = UIImage.init(named: "32621859132_25f783b550_o.jpg")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
//imageView.backgroundColor = .white
view.addSubview(imageView)
}
extension RestaurantDetailsVC : UITableViewDataSource, UITableViewDelegate
{
func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath) as! ItemCell
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 105
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
{
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemSectionCell") as! ItemSectionCell
cell.backgroundColor = .white
return cell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44
}
//Scrollview delegate
func scrollViewDidScroll(_ scrollView: UIScrollView)
{
let y = 200 - (scrollView.contentOffset.y + 200)
let height = min(max(y, 0), 300)
imageView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: height)
if height <= 0
{
UIView.animate(withDuration: Double(0.1), animations: {
self.constraintTopForViewBar.constant = 0
self.viewForTopBar.isHidden = false
self.view.layoutIfNeeded()
}) { (result) in}
self.tblItemList.contentInset = UIEdgeInsets(top: 68, left: 0, bottom: 0, right: 0)
}
else
{
UIView.animate(withDuration: Double(0.1), animations: {
self.constraintTopForViewBar.constant = -68
self.viewForTopBar.isHidden = true
self.view.layoutIfNeeded()
}) { (result) in}
self.tblItemList.contentInset = UIEdgeInsets(top: 200, left: 0, bottom: 0, right: 0)
}
//print(height)
}
}