Skip to content

Instantly share code, notes, and snippets.

@alexshive
Last active August 29, 2015 14:08
Show Gist options
  • Save alexshive/92dfad209f62b5583702 to your computer and use it in GitHub Desktop.
Save alexshive/92dfad209f62b5583702 to your computer and use it in GitHub Desktop.
Facebook POP Swift Animation test. Box enlarges and centers on screen on button click.
//
// ViewController.swift
// FacebookPOPAnimationTest
//
// Created by Alex Shive on 10/29/14.
// Copyright (c) 2014 Alex. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var box: UIView!
var isFullScreen = true
let size:CGFloat = 3.0
let h:CGFloat = 100.0
let w:CGFloat = 100.0
var startX:CGFloat = 0
var startY:CGFloat = 0
override func viewDidLoad() {
super.viewDidLoad()
startX = box.frame.origin.x + box.frame.size.width/2
startY = box.frame.origin.y + box.frame.size.height/2
let recognizer = UITapGestureRecognizer(target: self, action:Selector("handleTap:"))
recognizer.delegate = self
box.addGestureRecognizer(recognizer)
}
func handleTap(recognizer: UITapGestureRecognizer) {
isFullScreen = !isFullScreen
fullScreenZoomAnimation()
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
func fullScreenZoomAnimation() {
let baseRect = CGRectMake(startX, startY, w, h)
box.pop_removeAllAnimations()
let positionAnimation = POPSpringAnimation(propertyNamed: kPOPLayerPosition)
positionAnimation.springBounciness = 10;
let scaleAnimation = POPSpringAnimation(propertyNamed: kPOPLayerScaleXY)
let center = NSValue(CGPoint: self.view.center)
if (!isFullScreen)
{
scaleAnimation.toValue = NSValue(CGSize: CGSizeMake(size, size))
positionAnimation.toValue = center
}
else
{
scaleAnimation.toValue = NSValue(CGSize: CGSizeMake(1, 1))
positionAnimation.toValue = NSValue(CGRect: baseRect)
}
box.layer.pop_addAnimation(positionAnimation, forKey: "positionAnimation")
box.layer.pop_addAnimation(scaleAnimation, forKey: "scaleAnimation")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment