 	
 	override func viewWillAppear(animated: Bool) {
 		super.viewWillAppear(animated)
-		view.addGestureRecognizer(pinchGestureRecognizer)
-		
-		layout.itemSize = computeItemSize()
-		layout.invalidateLayout()
-		collectionView.reloadData()
+		myView.viewWillAppear()
 	}
 
 	override func viewDidDisappear(animated: Bool) {
 		super.viewDidDisappear(animated)
-		view.removeGestureRecognizer(pinchGestureRecognizer)
-	}
-	
-	lazy var layout: FlowLayout = {
-		return self.createFlowLayout()
-	}()
-	
-	func computeItemSize() -> CGSize {
-		return CGSize(width: model.scaleRounded, height: CollectionViewModel.height)
-	}
-	
-	func createFlowLayout() -> FlowLayout {
-		let instance = FlowLayout()
-		instance.itemSize = computeItemSize()
-		instance.model = self.model
-		return instance
-	}
-	
-	lazy var collectionView: MyCollectionView = {
-		let instance = MyCollectionView(frame: CGRectZero, collectionViewLayout: self.layout)
-		instance.delegate = self
-		instance.dataSource = self
-		return instance
-	}()
-	
-	func scrollViewDidScroll(scrollView: UIScrollView) {
-		updateLabel()
-	}
-	
-	func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-		return model.count
-	}
-	
-	func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
-		let cell = collectionView.dequeueReusableCellWithReuseIdentifier(SliderCell.identifier, forIndexPath: indexPath) as! SliderCell
-		cell.label.text = String(indexPath.row % 10)
-		return cell
-	}
-}
+		myView.viewDidDisappear()
+	}
+}

		var frame = view.bounds
		frame.size.height = CollectionViewModel.height
		frame.origin.y = (view.bounds.height - frame.height) * 0.5
		collectionView.frame = frame
		

		let halfWidth = round(frame.width/2)-1
		collectionView.contentInset = UIEdgeInsets(top: 0, left: halfWidth, bottom: 0, right: halfWidth)

		
		titleLabel.sizeToFit()

				scrollToValue(value)
			}
			
			valueDidChange?()
		}
	}
	
	func computeItemSize() -> CGSize {
		return CGSize(width: model.scaleRounded, height: CollectionViewModel.height)
	}
	
	lazy var layout: FlowLayout = {
		let instance = FlowLayout()
		instance.scrollDirection = .Horizontal
		instance.minimumInteritemSpacing = 0
		instance.minimumLineSpacing = 0
		instance.sectionInset = UIEdgeInsetsZero
		instance.headerReferenceSize = CGSizeZero
		instance.footerReferenceSize = CGSizeZero
		instance.itemSize = self.computeItemSize()
		instance.model = self.model
		return instance
	}()
	
	lazy var collectionView: UICollectionView = {
		let instance = UICollectionView(frame: CGRectZero, collectionViewLayout: self.layout)
		instance.showsHorizontalScrollIndicator = false
		instance.showsVerticalScrollIndicator = false
		instance.backgroundColor = UIColor.blackColor()
		instance.bounces = false
		instance.alwaysBounceHorizontal = true
		instance.alwaysBounceVertical = false
		instance.registerClass(SliderCell.self, forCellWithReuseIdentifier: SliderCell.identifier)
		instance.contentInset = UIEdgeInsetsZero
		instance.delegate = self
		instance.dataSource = self
		return instance
	}()
	
	func scrollViewDidScroll(scrollView: UIScrollView) {
		valueDidChange?()
	}
	
	func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
		return model.count
	}
	
	func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
		let cell = collectionView.dequeueReusableCellWithReuseIdentifier(SliderCell.identifier, forIndexPath: indexPath) as! SliderCell
		cell.label.text = String(indexPath.row % 10)
		return cell
	}
}

class ScientificSliderViewController2: UIViewController {
	
	override func loadView() {
		super.loadView()
		self.automaticallyAdjustsScrollViewInsets = false
		
		view.backgroundColor = UIColor.lightGrayColor()
		view.addSubview(myView)
		view.addSubview(titleLabel)
		view.addSubview(valueLabel)
		view.addSubview(usageLabel)
	}
	
	lazy var myView: MyView = {
		let instance = MyView()
		instance.valueDidChange = { [weak self] in
			self?.updateLabel()
		}
		return instance
	}()
	
	lazy var usageLabel: UILabel = {
		let instance = UILabel()
		instance.text = "Pinch to adjust magnitude.\n\nPan left/right to adjust value."
		instance.numberOfLines = 0
		instance.textAlignment = .Center
		instance.font = UIFont.systemFontOfSize(17)
		return instance
	}()
	
	lazy var titleLabel: UILabel = {
		let instance = UILabel()
		instance.text = "Value"
		instance.numberOfLines = 0
		instance.textAlignment = .Left
		instance.font = UIFont.boldSystemFontOfSize(18)
		return instance
	}()
	
	lazy var valueLabel: UILabel = {
		let instance = UILabel()
		instance.text = "-"
		instance.numberOfLines = 0
		instance.textAlignment = .Right
		instance.font = UIFont.systemFontOfSize(20)
		return instance
	}()

	func updateLabel() {
		if let value = myView.value {
			valueLabel.text = String(format: "%.3f", value)
		} else {
			valueLabel.text = "---"
		}
	}
	
