Hi everybody,
to me occured the same problem as Rob said… is it possible that the “UIView.animate()” in XCode 12 is different when it comes to adding animations?
Chris says in the video, he is simply using the return button to insert “self.frontImageView.alpha = 0” - for me this seems to be handled different in the XCode 12 version… but maybe I am just too much of a beginner…
// TODO: Does NOT function properly - …card stays open
//
// CardCollectionViewCell.swift
// MatchApp2
//
// Created by Nina Klee on 24.11.20.
//
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 the card this cell represents
self.card = card
// Set the front image view to the view 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, .transitionFlipFromLeft] , completion: nil)
}
// Set the status of the card
card?.isFlipped = false
}
func remove() {
// Make the image views invisible
backImageView.alpha = 0
// TODO: Does NOT function properly - ...card stays open
UIView.animate(withDuration: 0.3, delay: 0.5, options: .curveEaseOut, animations: {
self.frontImageView.alpha = 0}, completion: nil)
}
Hi Chris, (you are all Chris+s ? )
thanks for your answer.
In my reply above I send you the complete code.
Unfortunately this is already my second try with the MatchApp and I always get stuck at Lection 27… (maybe with different problems, though)
I will work on the WarCardGame as you suggested.
Hahaha… There are only two Chris’s and I am the “other one” from Australia whereas Chris Ching is Canadian and based in Toronto.
I plugged your code into my version of the App and it works perfectly so there is no issue in that file so I’m not sure what the issue might be. Check the ViewController.swift file to make sure that you have the call to remove both the cards and that the variables are named correctly.