6 заметок с тегом
Animation
Parallax Effect with Motion Device
8 мая 2017, 14:54
Формула Parallax
var parallaxImageHeight: CGFloat { let maxOffset = (sqrt( cellHeight * cellHeight + 4 * parallaxSpeed * self.tableView.frame.height) - cellHeight) / 2 return maxOffset + self.cellHeight }
Нашёл клёвую конструкцию
14 апреля 2017, 12:29
typealias Animation = (TimeInterval, ()->Void)
let animation: Animation = (5.0, { })
internal class Node<T> { var data: T var next: Node<T>? init(data: T){ self.data = data } } internal struct Queue<T> { var first, last: Node<T>? mutating func dequeue() -> T? { let pop = first?.data first = first?.next if first == nil { last = nil } return pop } mutating func enqueue(data: T){ if last == nil { first = Node(data: data) last = first } else { last?.next = Node( data: data) last = last?.next } } }
var animations: Queue = Queue<Animation>()
Анимация прямо в playground.
14 апреля 2017, 12:02
Чтобы поиграться с анимацией не создавая проект приложения достаточно использовать playground
import UIKit import PlaygroundSupport let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0)) let circle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 50.0, height: 50.0)) circle.center = containerView.center circle.layer.cornerRadius = 25.0 let startingColor = UIColor(red: (253.0/255.0), green: (159.0/255.0), blue: (47.0/255.0), alpha: 1.0) circle.backgroundColor = startingColor containerView.addSubview(circle); let rectangle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 50.0, height: 50.0)) rectangle.center = containerView.center rectangle.layer.cornerRadius = 5.0 rectangle.backgroundColor = UIColor.white containerView.addSubview(rectangle) UIView.animate(withDuration: 2.0, animations: { () -> Void in let endingColor = UIColor(red: (255.0/255.0), green: (61.0/255.0), blue: (24.0/255.0), alpha: 1.0) circle.backgroundColor = endingColor let scaleTransform = CGAffineTransform(scaleX: 5.0, y: 5.0) circle.transform = scaleTransform let rotationTransform = CGAffineTransform(rotationAngle: 3.14) rectangle.transform = rotationTransform }) PlaygroundPage.current.liveView = containerView