Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation completion will not work under some circumstances #10

Closed
iaomw opened this issue Aug 4, 2015 · 4 comments
Closed

Animation completion will not work under some circumstances #10

iaomw opened this issue Aug 4, 2015 · 4 comments

Comments

@iaomw
Copy link

iaomw commented Aug 4, 2015

I need to remove all the animations on some layer under specific condition. But after I did something like this, it become impossible to add animation any more. How could I cancel all animation without hurt it?

self.spriteLayer.removeAllAnimations()
@icanzilb
Copy link
Owner

icanzilb commented Aug 4, 2015

can you please paste in a chunk of code of how you add the animations and how you remove them so I can try to reproduce the problem?

@iaomw
Copy link
Author

iaomw commented Aug 4, 2015

Sorry, not the same as I expected before. It something like that below. I will change the title. While I am touching too fast, the completion block will not work.

func transformToTouching() { //Response to touching event

    self.setHighlighted(true, animated: true)

    self.animationQueue.removeAll(keepCapacity: true)

    EAAnimationDelayed.animations.map {

        $0.cancelAnimationChain()
    }

    self.spriteLayer.removeAllAnimations()

    self.chainAnimation({ () -> Void in

        self.spriteLayer.fillColor = ...
        self.spriteLayer.path = ...

    }, duration: 0.3)
}

typealias AnimationBlock = () -> Void
typealias AnimationPiece = (animation:AnimationBlock, duration: NSTimeInterval)

var animating:Bool = false
var animationQueue = [AnimationPiece]()

func chainAnimation(animation: AnimationBlock, duration: NSTimeInterval) {

    self.animationQueue.append((animation:animation, duration: duration))

    self.feedAnimation()
}

func feedAnimation() {

    if self.animating {

        return
    }

    if let some = self.animationQueue.first {

        self.animationQueue.removeAtIndex(0)

        self.animating = true

        UIView.animateWithDuration(some.duration, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: some.animation, completion: { (done: Bool) -> Void in // Not work while too fast

            self.animating = false

            self.feedAnimation()
        })

    } else {

        return
    } //
}

@iaomw iaomw changed the title Animation will never work after removeAllAnimations() called Animation completion will not work under some circumstances Aug 4, 2015
@icanzilb
Copy link
Owner

icanzilb commented Aug 4, 2015

what I see at first sight is that you never actually use the EasyAnimation API to create chains - animateAndChainWithDuration(...). You can cancel only custom EA chains, since the "normal" animations you create with the UIKit API aren't cancelable (but not a bad idea to think if it's possible to do that). Review again the example in the README: https://github.com/icanzilb/EasyAnimation#cancel-chain-animations

@iaomw
Copy link
Author

iaomw commented Aug 5, 2015

I really want to use your chain, but it doesn't work out while I chain them from different place. #9
Oops, as the block, we can comment it, it doesn't matter for the phenomenon. 😂

EAAnimationDelayed.animations.map {

        $0.cancelAnimationChain()
}

@icanzilb icanzilb closed this as completed Oct 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants