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
//create a layer | |
let layerToAnimate = CALayer() | |
layerToAnimate.backgroundColor = UIColor.red.cgColor | |
layerToAnimate.frame = CGRect(x: 100, y: 200, width: 100, height: 100) | |
//create a "x" position changing animation | |
let positionAnimation = CASpringAnimation(keyPath: "position.x") | |
positionAnimation.damping = 6 //How much the spring motion will be damped | |
positionAnimation.toValue = 300 // In the end layer center will be in this position | |
positionAnimation.duration = 1 // Time needed to complete the animation |
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
//create a layer | |
let layerToAnimate = CALayer() | |
layerToAnimate.backgroundColor = UIColor.red.cgColor | |
layerToAnimate.frame = CGRect(x: 100, y: 200, width: 30, height: 30) | |
//create a scaling animation | |
let scaleAnimation = CAKeyframeAnimation(keyPath: "transform.scale") | |
scaleAnimation.duration = 2 //Total animation duration | |
scaleAnimation.keyTimes = [0, 0.2, 0.5, 1.0] //keytimes within the animation duration[0.0-1.0] | |
scaleAnimation.values = [0, 2, 1, 3] //scale value of the keyTimes provided to the animation |
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
//create a layer | |
let layerToAnimate = CALayer() | |
layerToAnimate.backgroundColor = UIColor.red.cgColor | |
layerToAnimate.frame = CGRect(x: 100, y: 200, width: 100, height: 100) | |
//create a "x" position changing animation | |
let positionAnimation = CABasicAnimation(keyPath: "position.x") | |
positionAnimation.toValue = 300 // In the end layer center will be in this position | |
positionAnimation.duration = 2 // Time needed to complete the animation |
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
//create a layer | |
let windowBorderLayer = CALayer() | |
//give it a frame | |
windowBorderLayer.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: 200, height: 200)) | |
//set a border | |
windowBorderLayer.borderColor = UIColor(patternImage: UIImage(named: "windowImage")!).cgColor | |
windowBorderLayer.borderWidth = 20 | |
//add to a view | |
animationView.layer.addSublayer(windowBorderLayer) |
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
//create a layer | |
let windowShadeLeft = CALayer() | |
//set the anchor point | |
windowShadeLeft.anchorPoint = CGPoint(x: 0, y: 0) | |
//give it a frame | |
windowShadeLeft.frame = CGRect(origin: CGPoint(x: 20, y: 20), size: CGSize(width: (200-40)/2, height: 200-40)) | |
//set a image for the layer | |
windowShadeLeft.contents = UIImage(named: "windowImage")?.cgImage | |
windowShadeLeft.contentsGravity = .resizeAspectFill | |
//mask to bounds, so that images doen't show outside the layer |
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
//create a layer | |
let windowShadeRight = CALayer() | |
//set it's anchor point | |
windowShadeRight.anchorPoint = CGPoint(x: 1, y: 0) | |
//set it's frame | |
windowShadeRight.frame = CGRect(origin: CGPoint(x: 100, y: 20), size: CGSize(width: (200-40)/2, height: 200-40)) | |
//masks to bounds, so that images doen't show outside the layer | |
windowShadeRight.masksToBounds = true | |
//set a image for the layer | |
windowShadeRight.contents = UIImage(named: "windowImage")?.cgImage |
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
let layer = CALayer() | |
layer.backgroundColor = UIColor.red.cgColor | |
layer.anchorPoint = CGPoint(x: 0.0, y: 0.0) | |
layer.frame = CGRect(x: 0, y: 0, width: 200, height: 100) | |
animationView.layer.addSublayer(layer) | |
let animation = CABasicAnimation(keyPath: "transform") | |
animation.duration = 2 | |
animation.toValue = CATransform3DRotate(CATransform3DIdentity, (25.0 * .pi/180), 0, 0, 1) | |
animation.fillMode = .forwards |
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
let layer = CALayer() | |
layer.backgroundColor = UIColor.red.cgColor | |
layer.frame = CGRect(x: 0, y: 0, width: 200, height: 100) | |
animationView.layer.addSublayer(layer) | |
let animation = CABasicAnimation(keyPath: "transform") | |
animation.duration = 2 | |
animation.toValue = CATransform3DRotate(CATransform3DIdentity, (25.0 * .pi/180), 0, 0, 1) | |
animation.fillMode = .forwards | |
animation.isRemovedOnCompletion = false |
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
let layer = CALayer() | |
layer.backgroundColor = UIColor.red.cgColor | |
layer.frame = CGRect(x: 0, y: 0, width: 200, height: 100) | |
animationView.layer.addSublayer(layer) | |
var transform = CATransform3DIdentity | |
transform = CATransform3DRotate(transform, (180 * .pi / 180), 0, 1, 0) | |
let animation = CABasicAnimation(keyPath: "transform") | |
animation.duration = 2 |
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
let layer = CALayer() | |
layer.backgroundColor = UIColor.red.cgColor | |
layer.frame = CGRect(x: 0, y: 0, width: 200, height: 100) | |
animationView.layer.addSublayer(layer) | |
var transform = CATransform3DIdentity | |
transform.m34 = -1.0/200 | |
transform = CATransform3DRotate(transform, 180.degreesToRadians, 0, 1, 0) | |
let animation = CABasicAnimation(keyPath: "transform") |
OlderNewer