Created
January 17, 2017 08:54
-
-
Save aoriani/93a50641d55b5a82ae3cb16bf009dfea to your computer and use it in GitHub Desktop.
Small example of property animations Raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// Animations | |
// | |
// Created by Andre Oriani on 1/16/17. | |
// Copyright © 2017 Orion. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var image: UIImageView! | |
@IBOutlet weak var image2: UIImageView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
override func viewDidAppear(_ animated: Bool) { | |
let animation = CABasicAnimation() | |
animation.keyPath = "position.x" | |
animation.fromValue = 16 | |
animation.toValue = 283 | |
animation.duration = 1 | |
let animation2 = CABasicAnimation() | |
animation2.keyPath = "transform.scale" | |
animation2.fromValue = 0.25 | |
animation2.toValue = 1.2 | |
animation2.duration = 1 | |
image.layer.add(animation2, forKey: "teste2") | |
let animation3 = CABasicAnimation() | |
animation3.keyPath = "opacity" | |
animation3.fromValue = 0.2 | |
animation3.toValue = 1.0 | |
animation3.duration = 1 | |
image.layer.add(animation3, forKey: "teste3") | |
let animation4 = CABasicAnimation() | |
animation4.keyPath = "position" | |
animation4.fromValue = CGPoint(x: 16, y: 325) | |
animation4.toValue = CGPoint(x: 125, y: 89) | |
animation4.duration = 1 | |
image2.layer.speed = 0 | |
image2.layer.add(animation4, forKey: "teste4") | |
let animation5 = CABasicAnimation() | |
animation5.keyPath = "transform.rotation.z" | |
animation5.fromValue = 0 | |
animation5.toValue = 2*3.14 | |
animation5.duration = 1 | |
image2.layer.add(animation5, forKey: "teste5") | |
image.layer.speed = 0 | |
image.layer.add(animation, forKey: "teste") | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
@IBAction func sliderValueChanged(_ sender: UISlider) { | |
NSLog("Slider \(sender.value)") | |
image.layer.timeOffset = CFTimeInterval(sender.value) | |
image2.layer.timeOffset = CFTimeInterval(sender.value) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment