结束后将 CollectionView 向左滚动应该会在右端打开另一个 View Controller 和相同的功能

Scrolling CollectionView to left after ending should open another View Controller & same functionality on right end

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

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)
        }
    }
}

上的答案不符合我要求的功能。

我是这样解决的:-

    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)
               }
           }
       }

}