ScrollView without using UIscrolView

2

Good I want to implement a scrollView but without using the UIScrollView . I can not use UIScrollView because CVCalendar has a problem with the Framework and when a ScrollView is added it stops working.

That's why I'm looking for some alternative to add the Scroll mediate code, if someone knows how to do it or that you provide me with a help link.

    
asked by Bogdan 21.02.2016 в 00:01
source

1 answer

1

Good, I leave you the following code and a link to the project that I have done to solve your doubt, it may not be the best solution, but I hope it serves you in some way. It's basically a UIView with a UIPanGestureRecognizer

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var scrollView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        addPanGesture()
    }

    func addPanGesture() {
        let panGesture = UIPanGestureRecognizer(target: self, action: #selector(didScroll))
        self.scrollView.addGestureRecognizer(panGesture)
    }

    func didScroll(sender : UIPanGestureRecognizer) {
        if sender.state == .recognized {

            let translation = sender.translation(in: self.scrollView).y
            let y = self.scrollView.frame.origin.y
            let scrollViewSize = self.scrollView.frame.size.height
            let viewSize = self.view.frame.size.height
            var newY = y + translation

            // These conditions avoids scrollView to leave the screen

            if newY > 0 {
                newY = 0
            } else if newY + scrollViewSize <  viewSize {
                newY = -scrollViewSize + viewSize
            }

            UIView.animate(withDuration: 0.5, animations: {

                self.scrollView.frame = CGRect(x: 0,
                                               y: newY,
                                               width: self.scrollView.frame.width,
                                               height: scrollViewSize)
            })
        }

    }
}
    
answered by 30.01.2017 в 11:55