Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 1.03 KB

README.md

File metadata and controls

33 lines (23 loc) · 1.03 KB

FMBMParallaxView

Complete UIImageView subclass with parallax scrolling created during the first world SwiftCrunch hackaton!

Gif with results

FMBMImageView example usage

class ExampleViewController: UIViewController, UIScrollViewDelegate {

    @IBOutlet var imageView: FMBMImageView
    @IBOutlet var scrollView: UIScrollView

    override func viewDidLoad() {
        super.viewDidLoad()

        imageView.clipsToBounds = true
        scrollView.contentSize = CGSizeMake(400, 400)
        scrollView.delegate = self
    }
    
    func scrollViewDidScroll(scrollView: UIScrollView!) {
        let deltaX = scrollView.contentSize.width - scrollView.frame.width
        let deltaY = scrollView.contentSize.height - scrollView.frame.height
        
        imageView.horizontalOffset = scrollView.contentOffset.y / deltaX
        imageView.verticalOffset = scrollView.contentOffset.x / deltaY
    }

}