``` import UIKit class BBPMainController: UIViewController, UIScrollViewDelegate { var scrollView: UIScrollView! var applocationScrollOverlayerAboveView: UIView! var applocationScrollOverlayerBelowView: UIView! var sectorsController: BBPSectorsController! var welcomeController: BBPWelcomeController!   var caseController: BBPCaseController! var applicationController: BBPApplicationController!       var wrController: BBPWrController!     override func viewDidLoad() { super.viewDidLoad() // Set background view.backgroundColor = UIColor.bird.slate // Create UI // Scroll View scrollView = UIScrollView() scrollView.translatesAutoresizingMaskIntoConstraints = false scrollView.isPagingEnabled = true scrollView.showsVerticalScrollIndicator = false scrollView.delegate = self view.insertSubview(scrollView, at: 0) view.addConstraint(NSLayoutConstraint(item: scrollView, attribute: .left, relatedBy: .equal, toItem: view, attribute: .left, multiplier: 1, constant: 0)) view.addConstraint(NSLayoutConstraint(item: scrollView, attribute: .right, relatedBy: .equal, toItem: view, attribute: .right, multiplier: 1, constant: 0)) view.addConstraint(NSLayoutConstraint(item: scrollView, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1, constant: 0)) view.addConstraint(NSLayoutConstraint(item: scrollView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)) // Page 0 (Post application above) - Overlayer 1 applocationScrollOverlayerAboveView = UIView() applocationScrollOverlayerAboveView.translatesAutoresizingMaskIntoConstraints = false applocationScrollOverlayerAboveView.backgroundColor = UIColor.black scrollView.addSubview(applocationScrollOverlayerAboveView) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerAboveView, attribute: .left, relatedBy: .equal, toItem: scrollView, attribute: .left, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerAboveView, attribute: .right, relatedBy: .equal, toItem: scrollView, attribute: .right, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerAboveView, attribute: .top, relatedBy: .equal, toItem: scrollView, attribute: .top, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerAboveView, attribute: .width, relatedBy: .equal, toItem: scrollView, attribute: .width, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerAboveView, attribute: .height, relatedBy: .equal, toItem: scrollView, attribute: .height, multiplier: 1, constant: 0))           // Page 1.5 (Sectors)           caseController = storyboard!.instantiateViewController(withIdentifier: "Case") as! BBPCaseController     caseController.view.translatesAutoresizingMaskIntoConstraints = false     scrollView.addSubview(caseController.view)     addChild(caseController)           scrollView.addConstraint(NSLayoutConstraint(item: caseController.view, attribute: .left, relatedBy: .equal, toItem: scrollView, attribute: .left, multiplier: 1, constant: 0))     scrollView.addConstraint(NSLayoutConstraint(item: caseController.view, attribute: .right, relatedBy: .equal, toItem: scrollView, attribute: .right, multiplier: 1, constant: 0))           scrollView.addConstraint(NSLayoutConstraint(item: caseController.view, attribute: .top, relatedBy: .equal, toItem: applocationScrollOverlayerAboveView, attribute: .bottom, multiplier: 1, constant: 0))           scrollView.addConstraint(NSLayoutConstraint(item: caseController.view, attribute: .width, relatedBy: .equal, toItem: scrollView, attribute: .width, multiplier: 1, constant: 0))     scrollView.addConstraint(NSLayoutConstraint(item: caseController.view, attribute: .height, relatedBy: .equal, toItem: scrollView, attribute: .height, multiplier: 1, constant: 0))       // Page 2 (Welcome) welcomeController = storyboard!.instantiateViewController(withIdentifier: "Welcome") as! BBPWelcomeController welcomeController.view.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(welcomeController.view) addChild(caseController) scrollView.addConstraint(NSLayoutConstraint(item: welcomeController.view, attribute: .left, relatedBy: .equal, toItem: scrollView, attribute: .left, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: welcomeController.view, attribute: .right, relatedBy: .equal, toItem: scrollView, attribute: .right, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: welcomeController.view, attribute: .top, relatedBy: .equal, toItem: caseController.view, attribute: .bottom, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: welcomeController.view, attribute: .width, relatedBy: .equal, toItem: scrollView, attribute: .width, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: welcomeController.view, attribute: .height, relatedBy: .equal, toItem: scrollView, attribute: .height, multiplier: 1, constant: 0))             // Page 3 (Post application) - Overlayer 2 applocationScrollOverlayerBelowView = UIView() applocationScrollOverlayerBelowView.translatesAutoresizingMaskIntoConstraints = false applocationScrollOverlayerBelowView.backgroundColor = UIColor.black scrollView.addSubview(applocationScrollOverlayerBelowView) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerBelowView, attribute: .left, relatedBy: .equal, toItem: scrollView, attribute: .left, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerBelowView, attribute: .right, relatedBy: .equal, toItem: scrollView, attribute: .right, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerBelowView, attribute: .top, relatedBy: .equal, toItem: welcomeController.view, attribute: .bottom, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerBelowView, attribute: .bottom, relatedBy: .equal, toItem: scrollView, attribute: .bottom, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerBelowView, attribute: .width, relatedBy: .equal, toItem: scrollView, attribute: .width, multiplier: 1, constant: 0)) scrollView.addConstraint(NSLayoutConstraint(item: applocationScrollOverlayerBelowView, attribute: .height, relatedBy: .equal, toItem: scrollView, attribute: .height, multiplier: 1, constant: 0)) // Page 3 (Post application) - Controller applicationController = storyboard!.instantiateViewController(withIdentifier: "PostApplication") as! BBPApplicationController applicationController.mainController = self applicationController.view.translatesAutoresizingMaskIntoConstraints = false view.insertSubview(applicationController.view, belowSubview: scrollView) addChild(applicationController) view.addConstraint(NSLayoutConstraint(item: applicationController.view, attribute: .left, relatedBy: .equal, toItem: view, attribute: .left, multiplier: 1, constant: 0)) view.addConstraint(NSLayoutConstraint(item: applicationController.view, attribute: .right, relatedBy: .equal, toItem: view, attribute: .right, multiplier: 1, constant: 0)) view.addConstraint(NSLayoutConstraint(item: applicationController.view, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1, constant: 0)) view.addConstraint(NSLayoutConstraint(item: applicationController.view, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)) } var firstView = true override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // Scroll to default if firstView { firstView = false scrollView.contentOffset = CGPoint(x: 0, y: view.bounds.height * 2) } } // MARK: - Status bar override var prefersStatusBarHidden : Bool { return true } // MARK: - Scrolling func scrollViewDidScroll(_ scrollView: UIScrollView) { // -- Update overlayer alpha value -- let maxAlphaValue: CGFloat = 0.75 // Calcuate alpha let aboveAlpha = 0 - (maxAlphaValue - maxAlphaValue * ((scrollView.contentOffset.y - view.bounds.height) / view.bounds.height)) + maxAlphaValue * 2 let belowAlpha = maxAlphaValue - maxAlphaValue * ((scrollView.contentOffset.y - view.bounds.height) / view.bounds.height) + maxAlphaValue // Set alpha or 0 if alpha is greater than 1 applocationScrollOverlayerAboveView.alpha = aboveAlpha > 1 ? 0 : max(0, min(1, aboveAlpha)) applocationScrollOverlayerBelowView.alpha = belowAlpha > 1 ? 0 : max(0, min(1, belowAlpha)) // -- Update transform scale and view alpha value -- let minScaleValue: CGFloat = 0.6 let scale: CGFloat if aboveAlpha > 1 { scale = ((scrollView.contentOffset.y - view.bounds.height * 2) / view.bounds.height) * minScaleValue + abs(minScaleValue - 1) } else { scale = 0 - ((scrollView.contentOffset.y - view.bounds.height) / view.bounds.height) * minScaleValue + abs(minScaleValue - 1) } applicationController.view.transform = CGAffineTransform(scaleX: scale, y: scale) applicationController.view.alpha = max(0, min(1, scale)) } func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { userDidCompleteScrollDrag() } func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { if !decelerate { userDidCompleteScrollDrag() } } var prevScrollPositionWasAbove = false func userDidCompleteScrollDrag() { let atSectors = scrollView.contentOffset.y == view.bounds.height let atApplicationAbove = scrollView.contentOffset.y <= 0 let atApplicationBelow = scrollView.contentOffset.y >= view.bounds.height * 3 // Hide scrollview if application view is on top if atApplicationAbove || atApplicationBelow { scrollView.isHidden = true prevScrollPositionWasAbove = atApplicationAbove applicationController.viewDidBecomeFirst() } // Start intro movie if at sectors view else if atSectors { //caseController.playIntroMovie() } // Must be welcome view else { //sectorsController.resetIntroMovieView() } } // MARK: - Scrolling func scrollToDefault(delay: TimeInterval = 0) { scrollView.isHidden = false UIView.setAnimationsEnabled(true) // When is animations disabled ?? UIView.animate(withDuration: 0.3, delay: delay, options: [], animations: { self.scrollView.contentOffset = CGPoint(x: 0, y: self.view.bounds.height * (self.prevScrollPositionWasAbove ? 1 : 2)) }, completion: nil) } var applicationControllerVisible: Bool { return scrollView.contentOffset.y <= 0 || scrollView.contentOffset.y >= view.bounds.height * 3 } } ```