ios - 为什么我的滚动不适用于 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 中不起作用。
我在哪里错了..请帮忙...我被困在这里很久了
解决方案
推荐阅读
- ios - 当所有单元格的大小不同时,如何使 UICollectionView 的单元格换行?
- html - 侧边菜单在 Internet Explorer 11 中不可见
- bing-maps - 如何以较低的分辨率渲染 Bing 地图图块以在 Openlayers 上缩放大于最大值
- c# - 如何在 ASP.Net Core 2.x 中访问服务器变量
- mongodb - tomcat 服务器在启动时忽略加载 persistence.xml(HIbernate OGM、Mongodb、Spring boot)
- cmake - Coverity CMake 构建错误
- powerbi - 如何为 PowerBI 上的报告获取嵌入访问令牌?
- typescript - 有条件地重定向抛出错误
- laravel-5.6 - Laravel 工厂 - 使用工厂中的状态
- scala - 如何在使用 grpc 依赖项时加载 spark ml 模型?