private func changeColor(_ color: UIColor) {
UIView.animate(withDuration: self.duration, animations: {
self.animateView.backgroundColor = color
}, completion: nil)
}
private func rotateView(_ angel: Double) {
UIView.animate(withDuration: duration, delay: delay, options: [.repeat], animations: {
self.animateView.transform = CGAffineTransform(rotationAngle: CGFloat(angel))
}, completion: nil)
}
CGAffineTransform
๋ทฐ์ ํ๋ ์์ ๊ณ์ฐํ์ง ์๊ณ 2D ๊ทธ๋ํฝ์ ๊ทธ๋ ค์ค๋ค.
๊ฐ์ฒด๋ฅผ ํ์ , ํฌ๊ธฐ ์กฐ์ , ๋ณํ ๋๋ ๊ธฐ์ธ์ด๋ ๋ฐ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
private func multiColor(_ firstColor: UIColor, _ secondColor: UIColor) {
UIView.animate(withDuration: duration, animations: {
self.animateView.backgroundColor = firstColor
}, completion: { finished in
self.changeColor(secondColor)
})
}
private func multiPosition(_ firstPosition: CGPoint, _ secondPosition: CGPoint) {
func simplePosition(_ position: CGPoint) {
UIView.animate(withDuration: self.duration, animations: {
self.animateView.frame.origin = position
}, completion: nil)
}
UIView.animate(withDuration: self.duration, animations: {
self.animateView.frame.origin = firstPosition
}, completion: { finished in
simplePosition(secondPosition)
})
}
private func curvePath(_ endPoint: CGPoint, controlPoint1: CGPoint, controlPoint2: CGPoint) {
let path = UIBezierPath()
path.move(to: self.animateView.center)
path.addCurve(to: endPoint, controlPoint1: controlPoint1, controlPoint2: controlPoint2)
let anim = CAKeyframeAnimation(keyPath: "position")
anim.path = path.cgPath
anim.duration = self.duration
self.animateView.layer.add(anim, forKey: "animate position along path")
self.animateView.center = endPoint
}
UIBezierPath
์ง์ ๋ฐ ๊ณก์ ์ผ๋ก ๋ path ์ปค์คํ
CAKeyframeAnimation
ํน์ ์๊ฐ(ํค ํ๋ ์)์ ๊ฐ์ฒด๊ฐ ๊ฐ์ ธ์ผ ํ ๊ฐ์ ์ง์ ํ๊ณ , ๊ทธ ์ฌ์ด์ ๊ฐ์ ๋ณด๊ฐ(interpolation)ํ๋ ๋ฐฉ๋ฒ์ผ๋ก ๊ตฌํ
์๋ฅผ ๋ค์ด, ๊ณต์ด ํ์ด์ฌ๋์ ๋๋ฅผ ๊ฐ์ ํ๋ฉด, ๊ณต ์์น ์ด๊ธฐ๊ฐ, ํ์ด ์ค๋ฅธ ์ต๋๊ฐ, ๋ค์ ๋ฐ๋ฅ์ ๋จ์ด์ก์ ๋์ ๊ฐ๋ง ์ง์ ํ๊ณ ๋๋จธ์ง ๊ฐ์ ์๋์ผ๋ก ๊ณ์ฐ๋๋๋ก ํด์ค๋ค.
private func colorFrameChange(_ firstFrame: CGRect, _ secondFrame: CGRect, _ thirdFrame: CGRect, _ firstColor: UIColor, _ secondColor: UIColor, _ thirdColor: UIColor) {
UIView.animate(withDuration: self.duration, animations: {
self.animateView.backgroundColor = firstColor
self.animateView.frame = firstFrame
}, completion: { finished in
UIView.animate(withDuration: self.duration, animations: {
self.animateView.backgroundColor = secondColor
self.animateView.frame = secondFrame
}, completion: { finished in
UIView.animate(withDuration: self.duration, animations: {
self.animateView.backgroundColor = thirdColor
self.animateView.frame = thirdFrame
}, completion: nil)
})
})
}
private func viewFadeIn() {
let secondView = UIImageView(image: UIImage(named: "2"))
secondView.frame = self.animateView.frame
secondView.alpha = 0.0
view.insertSubview(secondView, aboveSubview: self.animateView)
UIView.animate(withDuration: duration, delay: delay, options: .curveEaseOut, animations: {
secondView.alpha = 1.0
self.animateView.alpha = 0.0
}, completion: nil)
}
private func Pop() {
UIView.animate(withDuration: duration / 4, animations: {
self.animateView.transform = CGAffineTransform(scaleX: CGFloat(self.scale), y: CGFloat(self.scale))
}, completion: { finished in
UIView.animate(withDuration: self.duration / 4, animations: {
self.animateView.transform = CGAffineTransform.identity
})
})
}
CGAffineTransform.identity
์๋ ์ํ๋ก ๋๋๋ฆฌ๊ธฐ
private func animation(_ view: UIView) {
let scaleAnimation = CGAffineTransform(scaleX: 2.0, y: 2.0)
let rotateAnimation = CGAffineTransform(rotationAngle: .pi)
let moveAnimation = CGAffineTransform(translationX: 0, y: -200)
let concat = scaleAnimation.concatenating(rotateAnimation).concatenating(moveAnimation)
UIView.animate(withDuration: 1, delay: 1, options: [], animations: {
view.transform = concat
}, completion: nil)
}