UIPageViewController内的UICollectionViewCell内的UIScrollView,具有滚动边缘页面的寻呼机

时间:2019-07-11 11:26:37

标签: swift uiscrollview uigesturerecognizer uipageviewcontroller

这有点令人困惑。我有这样一个要求:制作一个具有UIPageViewController且每个页面中都包含UICollectionView的应用程序。

每个UICollectionView都包含一个内部带有UIScrollView的单元格。

我需要这种行为: 当用户滚动单元格时,它将滚动内容,而当内容到达边缘时(它会自然反弹),我希望寻呼机开始翻转到下一页。

现在,将发生以下情况: 用户滚动,当到达边缘时,它会跳动UIScrollView,但不会转到下一页。

不用说,当我将内容大小设置为与scrollView本身大小完全相同时(意味着没有要平移的内容),它将执行页面操作。

我读了很多问题,试图获得相似的结果,但这完全不是我的要求。

一些代码段

包含滚动视图的单元格:

class ScrollingCell: UICollectionViewCell, UIGestureRecognizerDelegate {

    @IBOutlet weak var scrollView: SpecialScrollView!
    var panGesture : UIPanGestureRecognizer!

    override func awakeFromNib() {
        super.awakeFromNib()
        panGesture = UIPanGestureRecognizer.init(target: self, action: nil)
        addGestureRecognizer(panGesture)
    }

    @objc func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }

}

然后,在委派UIViewController的{​​{1}}中:

UICollectionView

最后是class UIColViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIGestureRecognizerDelegate { var panGesture : UIPanGestureRecognizer! func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 2 } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { if indexPath.row == 0 { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ScrollingCell", for: indexPath) as! ScrollingCell cell.panGesture.delegate = self return cell } let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NotScrollCell", for: indexPath) as! NotScrollCell return cell } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: collectionView.frame.width, height: collectionView.frame.height / 2) } @IBOutlet weak var collectionView: UICollectionView! var vcIndex: Int? = nil override func viewDidLoad() { super.viewDidLoad() collectionView.register(UINib(nibName: "ScrollingCell", bundle: nil), forCellWithReuseIdentifier: "ScrollingCell") collectionView.register(UINib(nibName: "NotScrollCell", bundle: nil), forCellWithReuseIdentifier: "NotScrollCell") collectionView.delegate = self collectionView.dataSource = self collectionView.reloadData() panGesture = UIPanGestureRecognizer.init(target: self, action: nil) collectionView.addGestureRecognizer(panGesture) } @objc func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } }

UIPageViewController

}

0 个答案:

没有答案