Skip to content

Instantly share code, notes, and snippets.

@tfrank64
Last active May 11, 2016 11:46
Show Gist options
  • Save tfrank64/e0d78df2c85268e1da85 to your computer and use it in GitHub Desktop.
Save tfrank64/e0d78df2c85268e1da85 to your computer and use it in GitHub Desktop.
UI experiment using CRPixellatedView and the basic layout of MGSpotyViewController
//
// PixelViewController.swift
//
// Created by Taylor Franklin
//
import UIKit
class PixelViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var imageView: CRPixellatedView!
var overView: UIView!
var startOffset: CGPoint!
var pulled: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
var view = UIView(frame: UIScreen.mainScreen().bounds)
view.backgroundColor = UIColor.lightGrayColor()
imageView = CRPixellatedView(frame: CGRectMake(0, 0, view.frame.size.width, view.frame.size.width))
imageView.contentMode = UIViewContentMode.ScaleAspectFill
imageView.image = UIImage(named: "cat.jpg")
imageView.animationDuration = 0.4
imageView.pixelScale = 15.0
view.addSubview(imageView)
overView = UIView(frame: imageView.bounds)
overView.backgroundColor = UIColor.clearColor()
view.addSubview(overView)
var table = UITableView(frame: view.frame)
table.delegate = self
table.dataSource = self
table.backgroundColor = UIColor.clearColor()
view.addSubview(table)
startOffset = table.contentOffset
self.view = view
}
func scrollViewDidScroll(scrollView: UIScrollView) {
if scrollView.contentOffset.y < startOffset.y {
var absoluteY = abs(scrollView.contentOffset.y)
var diff = startOffset.y - scrollView.contentOffset.y
imageView.frame = CGRectMake(0.0-diff/2.0, 0.0, overView.frame.size.width+absoluteY, overView.frame.size.width+absoluteY)
overView.frame = CGRectMake(0.0, 0.0+absoluteY, overView.frame.size.width, overView.frame.size.height)
if !pulled && diff > 35.0 {
imageView.reverse = false
imageView.animate()
pulled = true
}
} else if scrollView.contentOffset.y >= startOffset.y && pulled {
imageView.reverse = true
imageView.animate()
pulled = false
}
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
var transparent = UIView(frame: overView.bounds)
transparent.backgroundColor = UIColor.clearColor()
return transparent
}
return nil
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 0 {
return overView.frame.size.height
}
return 0
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 12;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCellWithIdentifier("cellID") as? UITableViewCell {
return cell
}
let cell = UITableViewCell()
cell.textLabel?.text = "I am a Cell"
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment