Use Pan Recognizer to Control ScrollView

本小妞迷上赌 提交于 2020-01-06 07:17:48

问题


I have a scrollView with paging enables. I have a UIView as a subview of the scrollView. When the scrollView reaches the buttom of it's content, I'm turning scrolling off:

scrollView.scrollEnabled = false

because I'm doing other things that require dragging in a part of the scrollView (Yellow part). So the scrollViews offset locks at the buttom of the page. I want to be able to drag in the UIView (red), to enable scrolling of the scrollView, and thereby change the scrollviews content offset.

So I've added a UIPanGestureRecognizer to the UIView, which action enables scrolling of the scrollview. The problem is that, when I start panning on the UIView, I have to lift the finger and put it down again, before I can drag the scrollView.

Here's some code:

var scrollView: UIScrollView!
var someView: UIView!
var panAGes: UIGestureRecognizer!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    scrollView = UIScrollView(frame: CGRectMake(0, 0, view.frame.width, view.frame.height))
    scrollView.contentSize = CGSizeMake(view.frame.width, view.frame.height * 2)
    scrollView.pagingEnabled = true
    scrollView.delegate = self
    someView = UIView(frame: CGRectMake(0, view.frame.height, view.frame.width, 100))
    someView.backgroundColor = UIColor.yellowColor()
    panAGes = UIPanGestureRecognizer(target: self, action: "panning:")

    someView.addGestureRecognizer(panAGes)
    scrollView.addSubview(someView)
    self.view.addSubview(scrollView)
 }

func scrollViewDidScroll(scrollView: UIScrollView) {
    // when page is locked
    if scrollView.contentOffset.y >= view.frame.height {
        scrollView.scrollEnabled = false
    }        
}

func panning(gesture: UIGestureRecognizer) {
        scrollView.scrollEnabled = true
}

How can I make the scrollView scroll, when the panning method is called? Thank You...

来源:https://stackoverflow.com/questions/33046469/use-pan-recognizer-to-control-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!