Unable to see animation for .transitionFlipFromRight for first 3 view controllers in array

I have an application with a Tinder-like interface where the user can turn the car over

In my ViewController.swift I have

private var currentCardsOnScreen: [CardViewController] = []

This array is populated when I CardViewController the stack:

 if !currentCardsOnScreen.map({ $0.id }).contains(vc.id) { self.currentCardsOnScreen.append(vc) } 

And the items are deleted after scrolling:

 if let index = currentCardsOnScreen.index(of: currentCard), currentCardsOnScreen.map({ $0.id }).contains(currentCard.id) { currentCardsOnScreen.remove(at: index) } 

When the user selects a map, I launch it:

 guard let currentCard = currentCard(index: index) else { return } currentCard.flipCard() 

Which call calls this method:

 func flipCard() { guard let frontOfCard = frontOfCard, let backOfCard = backOfCard else { return } UIView.animate(withDuration: 0.32, delay: 0, options: .transitionFlipFromRight, animations: { if self.frontIsShowing { self.view.transform = CGAffineTransform(scaleX: 1, y: 1) frontOfCard.alpha = 0 backOfCard.view.alpha = 1 } else { self.view.transform = CGAffineTransform(scaleX: -1, y: 1) frontOfCard.transform = CGAffineTransform(scaleX: -1, y: 1) frontOfCard.alpha = 1 backOfCard.view.alpha = 0 } self.frontIsShowing = !self.frontIsShowing }, completion: nil) 

The number of cards in the stack is always equal to 3. For the first 3 cards, clicking on the card will change the value of frontIsShowing , but will not display the flip card. If I delete the first 3, any card after that will behave as intended. Animation will show, and everything will be fine.

Any ideas what can be done here?

Edit: Also, not sure if it is connected, but on map 4, when it does the first flip animation, I see the alpha transition through the fade in / fade out, but not the flip of the card. In the second click, I see this flip animation. Again, not sure if I were connected, but thought I mentioned.

+5
source share
2 answers

I get it. I had a call to Alamofire to get a large piece of data that blocked the main stream from the animation

+4
source

flipCard () calls the main thread and retrieves data in the background thread

 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // fetch data in background thread }); 
+1
source

Source: https://habr.com/ru/post/1272856/


All Articles