首页 > 解决方案 > 为什么我的滚动不适用于 iOS Swift 中的 iPhone 12 和 iPhone 11

问题描述

使用下面的代码,我可以在 iPhone 8 中滚动单元格,但是当我在 iPhone12 和 iPhone11 中运行此代码时,它不会滚动,但委托方法正在调用

这里count的参数是 page.. 每次它显示 10 个单元格.. 就像.. 当我最初到达这个屏幕时,它显示 10 个单元格,如果还有更多产品的话。它没有滚动

override func viewDidLoad() {
 super.viewDidLoad()
 // using framework
 let bottomRefreshController = UIRefreshControl()
 bottomRefreshController.triggerVerticalOffset = 50
 bottomRefreshController.addTarget(self, action: #selector(refresh), for: .valueChanged)
 self.collectionView.bottomRefreshControl = bottomRefreshController
 self.collectionView.bottomRefreshControl?.tintColor = .clear
 }


 @objc func refresh() {
 serviceCall()
 }


  fileprivate func allProductsServiceCall(){

 let param = ["params": ["category" : catId,
                         "sub_category" : self.subCatId,
                         "brands": brands,
                         "count" : self.currentPageNumber

              ]] as [String : Any]
 APIReqeustManager.sharedInstance.serviceCall(param: param, vc: self, url: getUrl(of: .all_products/*.search*/), header: header) {(responseData) in
     
     if responseData.error != nil{
         self.view.makeToast(NSLocalizedString("Something went wrong!", comment: ""))
     }else{
         if (SearchDataModel(dictionary: responseData.dict as NSDictionary? ?? NSDictionary())?.result?.products ?? [Products]()).count == 0 {
             self.view.makeToast("No product to show!".localizeWithLanguage)
             return
         }
         if self.currentPageNumber > 0 {
             if (SearchDataModel(dictionary: responseData.dict as NSDictionary? ?? NSDictionary())?.result?.products ?? [Products]()).count > 0 {
                 self.searchResultData?.result?.products! += SearchDataModel(dictionary: responseData.dict as NSDictionary? ?? NSDictionary())?.result?.products ?? [Products]()
             }else {
                 self.view.makeToast("No more products to show!".localizeWithLanguage)
             }
             
             self.productCollectionView.bottomRefreshControl?.endRefreshing()
       
         self.currentPageNumber+=1
         
         DispatchQueue.main.async{
         self.productCollectionView.reloadData()
         }
     }
 }
 }


// Scroll delegates
// Things needed for expand / collapse
func scrollViewDidScroll(_ scrollView: UIScrollView) {

if scrollView == productCollectionView {
    let delta = scrollView.contentOffset.y - lastContentOffset
    if delta < 0 {
        // move up
        if scrollView.contentOffset.y <= (-self.range.lowerBound) {
            print("at the top")
            self.productCollectionView.bounces = false
            topConstraint.constant = min(topConstraint.constant - (delta), range.upperBound)
        }else {
            print("at the middle, moving up")
        }
    } else {
        // move down
        topConstraint.constant = max(range.lowerBound, topConstraint.constant - (delta))
        if (scrollView.contentOffset.y + scrollView.frame.size.height) == scrollView.contentSize.height {
          print("at the end")
            self.productCollectionView.bounces = true
        }else {
          print("at the middle, moving down")
        }
    }
    lastContentOffset = scrollView.contentOffset.y
}
}

代码工作正常。我的意思是我想如何在 iPhone8 中展示它的出现,但是,为什么带有分页的滚动在 iPhone12 中不起作用。

我在哪里错了..请帮忙...我被困在这里很久了

标签: iosswiftxcodescroll

解决方案


推荐阅读