结束后向左滚动 CollectionView 应该会在右端打开另一个视图控制器和相同的功能



我有一个集合视图,其中有4-5张图像,其滚动方向是水平的。我想在两侧(即左右(滚动结束后推送到视图控制器。如果用户位于集合视图的最左侧图像上并尝试再次向右滑动,那么它应该推送到新的视图控制器,并且同样在右侧。到目前为止,我已经尝试过了:-

func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
for cell in self.qrCodeCollctionView.visibleCells{
let indexPaths = self.qrCodeCollctionView.indexPath(for: cell)
if indexPaths!.row == 0{
var cellInsets = UIEdgeInsets()
if #available(iOS 11.0, *) {
cellInsets = cell.safeAreaInsets
} else {
// Fallback on earlier versions
}
print(cellInsets)
}
}
}

Swift 4 UICollectionView 检测滚动结束的答案不符合我所需的功能。

我用这种方式解决了它:-

func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
let contentOffsetX = scrollView.contentOffset.x
for cell in self.qrCodeCollctionView.visibleCells {
let indexPath = self.qrCodeCollctionView.indexPath(for: cell)
if indexPath?.row == 0{
if contentOffsetX < -50{
let vc = UIStoryboard(name: "Main", bundle:    nil).instantiateViewController(withIdentifier: "MyViewController") as!    MyViewController
self.navigationController?.pushViewController(vc, animated: true)
}
}
else if indexPath?.row == (self.qrCodeDataArray.count - 1){
if contentOffsetX > (scrollView.contentSize.width - scrollView.bounds.width) - 20{
print("over right")
self.scrollViewDidEndDecelerating(self.qrCodeCollctionView)
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MyViewController") as! MyViewController
let navController = UINavigationController(rootViewController: vc)
vc.ContactFromVC = self.currentContact
vc.currentIndexVC = self.currentIndex
vc.delegateContact = self
self.present(navController, animated: true, completion: nil)
}
}
}
}

相关内容

  • 没有找到相关文章

最新更新