Hi all,
Thank you Chris for your course! It has been amazing thus far and I completed it today.
However, when using the MatchApp, there is still a slight error I am not able to resolve as a beginner. I have compared my code to Chris’ code, but I haven’t seen anything looking different.
When selecting the first card (top left) and scroll all the way down to select the 16th card (bottom right) it still looks for a match and if not, it will turn card 16 back. However, when returning to card 1, it remains open and unusable.
This is the code written in CardCollectionViewCell.swift
import UIKit
class CardCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var frontImageView: UIImageView!
@IBOutlet weak var backImageView: UIImageView!
var card:Card?
func configureCell(card:Card){
// Keep track of card this cell represents
self.card = card
// Set the front image view to the image that represents the card
frontImageView.image = UIImage(named: card.imageName)
// Reset the state of the cell by checking the flipped status of the card and then showing the front or the back imageview accordingly
if card.isMatched == true{
backImageView.alpha = 0
frontImageView.alpha = 0
return
}
else {
backImageView.alpha = 1
frontImageView.alpha = 1
}
if card.isFlipped == true{
// Show the front image view
flipUp(speed: 0)
}
else {
// Show the back image view
flipDown(speed: 0, delay: 0)
}
}
func flipUp(speed: TimeInterval = 0.3) {
// Flip up animation
UIView.transition(from: backImageView, to: frontImageView, duration: speed, options: [.showHideTransitionViews, .transitionFlipFromLeft], completion: nil)
// Set the status of the card
card?.isFlipped = true
}
func flipDown(speed: TimeInterval = 0.3, delay:TimeInterval = 0.5) {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay) {
// Flip down animation
UIView.transition(from: self.frontImageView, to: self.backImageView, duration: speed, options: [.showHideTransitionViews, .transitionFlipFromRight], completion: nil)
}
// Set the status of the card
card?.isFlipped = false
}
func remove() {
// Make the image views invisible
backImageView.alpha = 0
UIView.animate(withDuration: 0.3, delay: 0.5, options: .curveEaseOut, animations: {
self.frontImageView.alpha = 0
}, completion: nil)
}
}
Hopefully, someone will be able to help me! Thanks in advance.
- Rob