EZSwipeController icon indicating copy to clipboard operation
EZSwipeController copied to clipboard

disable scroll when reaches the most left or right view controller

Open ghost opened this issue 7 years ago • 3 comments

It will be nicer if we can disable the scroll to make it more like snapchat style.

ghost avatar Oct 19 '16 23:10 ghost

Its more like tinder style atm

Esqarrouth avatar Oct 20 '16 06:10 Esqarrouth

Thanks for the great project, I have used EZSwipeController successfully in my own project, which has three viewcontrollers and the left most one is for message and the right most one is for system setting, so it's important for me to disable scrolling when it's in message or setting sections, because otherwise it's quite ugly. I successfully achieved this by implementing the delegate of UIScrollViewDelegate as

extension MySwipeVC: UIScrollViewDelegate {
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if self.currentVCIndex == 0 && (scrollView.contentOffset.x < scrollView.bounds.size.width) {
            scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
        } else if self.currentVCIndex == self.stackVC.count - 1 && (scrollView.contentOffset.x > scrollView.bounds.size.width) {
            scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
        }
    }

    func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        if self.currentVCIndex == 0 && (scrollView.contentOffset.x < scrollView.bounds.size.width) {
            scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
        } else if self.currentVCIndex == self.stackVC.count - 1 && (scrollView.contentOffset.x > scrollView.bounds.size.width) {
            scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
        }
    }
}

And in viewWillAppear, I added

  override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        for someview in self.pageViewController.view.subviews {
            if someview is UIScrollView {
                let scrollview = someview as! UIScrollView
                scrollview.delegate = self
            }
        }
    }

To make this actually work, in EZSwipeController, it should update currentStackVC after pageViewController completed setViewControllers, I have made a PR in case other people need the same feature as I.

ghost avatar Oct 21 '16 05:10 ghost

@liyukuang did you by any chance initialize a UITableViewController in the EZSwipeController? I opened a similar issue because I have an array of objects (n) that sorts out which UITableViewController to show. But is it even possible to initialize multiple, and unknown numbers of UITableViewControllers in this???

HackShitUp avatar Dec 27 '16 07:12 HackShitUp