Skip to content

Instantly share code, notes, and snippets.

View Xiomara7's full-sized avatar
🎯

Xiomara Figueroa Xiomara7

🎯
View GitHub Profile
extension GameController: MemoryGameProtocol {
func memoryGameDidStart(_ game: MemoryGame) {
collectionView.reloadData()
}
func memoryGame(_ game: MemoryGame, showCards cards: [Card]) {
for card in cards {
guard let index = game.indexForCard(card)
else { continue
}
UIView.animate(withDuration: 2.0, animations: { () -> Void in
// Move "appleImage" from current position to center
appleImage.center = containerView.center
// Change current background color to white
circle.backgroundColor = UIColor.white
})
let translate = CGAffineTransform(translationX: 100, y: 100)
let rotate = CGAffineTransform(rotationAngle: 360)
let scale = CGAffineTransform(scaleX: 5, y: 5)
//You can even combine 2 animations together.
circle.transform = translate.concatenating(rotate)
class Responder : NSObject {
func action() {
// On click
}
}
let responder = Responder()
let gesture = UITapGestureRecognizer(
target: responder,
action: #selector(Responder.action)
)
UIView.animate(
withDuration: 0.5,
delay: 0,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.8,
options: .curveEaseInOut,
animations: {
// Do animation
}, completion: nil)
UIView.animate(withDuration: 2.0, animations: { () -> Void in
circle.backgroundColor = UIColor.white
appleImage.center = containerView.center
})
let circle = UIView(
frame: CGRect(x: 0.0, y: 0.0, width: 64.0, height: 64.0)
)
circle.center = containerView.center
circle.backgroundColor = UIColor.blue
circle.layer.borderColor = UIColor.blue.cgColor
circle.layer.cornerRadius = 32.0
circle.layer.borderWidth = 2.0
containerView.addSubview(circle)
let appleImage = UIImageView(
frame: CGRect(x: 160.0, y: 0.0, width: 50.0, height: 60.0)
)
appleImage.image = UIImage(named: "apple")
containerView.addSubview(appleImage)
let containerView = UIView(
frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0)
)
containerView.backgroundColor = UIColor.white
platform :ios, '9.0'
use_frameworks!
pod 'PureLayout'