Add card wiggling animation loop
This commit is contained in:
parent
bf9547d804
commit
737a24e927
|
@ -35,13 +35,8 @@ class CardViewController: UIViewController {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Methods
|
||||||
|
|
||||||
// MARK: - Event handling
|
|
||||||
|
|
||||||
@objc func cardTapped(_ sender: UIGestureRecognizer) {
|
|
||||||
delegate.cardTapped(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func flipToReveal() {
|
@objc func flipToReveal() {
|
||||||
UIView.transition(
|
UIView.transition(
|
||||||
with: view,
|
with: view,
|
||||||
|
@ -62,6 +57,34 @@ class CardViewController: UIViewController {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@objc func wiggle() {
|
||||||
|
UIView.animate(
|
||||||
|
withDuration: 0.25,
|
||||||
|
delay: 0,
|
||||||
|
options: [.allowUserInteraction],
|
||||||
|
animations: { [weak self] in
|
||||||
|
self?.backImageView.transform = CGAffineTransform(
|
||||||
|
scaleX: 1.04, y: 1.04
|
||||||
|
).concatenating(
|
||||||
|
CGAffineTransform(rotationAngle: (6.6 / 180.0) * .pi)
|
||||||
|
).concatenating(
|
||||||
|
CGAffineTransform(rotationAngle: -(6.6 / 180.0) * .pi)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
completion: { [weak self] _ in
|
||||||
|
self?.backImageView.transform = CGAffineTransform.identity
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - Event handling
|
||||||
|
|
||||||
|
@objc func cardTapped(_ sender: UIGestureRecognizer) {
|
||||||
|
delegate.cardTapped(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// MARK: - Navigation
|
// MARK: - Navigation
|
||||||
|
|
|
@ -35,6 +35,10 @@ class HomeViewController: UIViewController {
|
||||||
|
|
||||||
setupBackground()
|
setupBackground()
|
||||||
loadCards()
|
loadCards()
|
||||||
|
setupWiggling()
|
||||||
|
playBackgroundMusic()
|
||||||
|
|
||||||
|
currentCardState = .allFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,8 +71,6 @@ class HomeViewController: UIViewController {
|
||||||
|
|
||||||
cardViewControllers.append(cardViewController)
|
cardViewControllers.append(cardViewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentCardState = .allFlat
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,6 +120,28 @@ class HomeViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func setupWiggling() {
|
||||||
|
cardViewControllers.forEach({ card in
|
||||||
|
perform(#selector(wiggle), with: card, afterDelay: Double.random(in: 0...10))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func wiggle(_ card: CardViewController) {
|
||||||
|
card.wiggle()
|
||||||
|
|
||||||
|
if Int.random(in: 0...1) == 1 {
|
||||||
|
perform(#selector(wiggle), with: card, afterDelay: Double.random(in: 1...2))
|
||||||
|
} else {
|
||||||
|
perform(#selector(wiggle), with: card, afterDelay: Double.random(in: 7...10))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func playBackgroundMusic() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Private functions
|
// MARK: - Private functions
|
||||||
|
|
||||||
private func makeCardPositions() -> [CGPoint] {
|
private func makeCardPositions() -> [CGPoint] {
|
||||||
|
|
Loading…
Reference in New Issue