Adding easing to animationStop? - framerjs

How can I add easing to the animationStop method?
Right now, when I call it the animation stops immediately, I want it to ease to a stop, just like it you hit the brakes on a car.
Any ideas how I could approach that?

Related

Animate view and stop midway

I want to make a view/header collaspe/expand animation, but I also want to be able to pause or stop from expanding/collapsing while the user takes his finger off the screen.
I have a current implementation for this, but the animation is not very smooth.
I will also add some images to explain better what I want to do.
So the first image is how it should look when expanded.
The second image is how it should look if the user decides to take take his finger off the screen while he would scroll slowly so the animation/the view should stop in a state similar to that.
The third image is how it should look when it is collapsed.
If someone has any recommendation how I could achieve this I would be very grateful.
If you are targeting iOS 10+, use UIViewPropertyAnimator which encapsulates an animation and allows scrubbing and controlling the animation:
Start, pause, resume, and stop animations; see the methods of the UIViewAnimating protocol.
Add animation blocks after the original animations start using the addAnimations(_:) and addAnimations(_:delayFactor:) methods.
Scrub through a paused animation by modifying the fractionComplete property.
Change the animation’s direction using the isReversed property.
Modify the timing and duration of a partially complete animation by pausing the animation and using the continueAnimation(withTimingParameters:durationFactor:) method to finish it.
You just need to wire up touches to UIViewPropertyAnimator object encapsulating the animation.
There are many good tutorials on how to start with it, e.g. this one.

How to terminate a SCNTransaction ongoing?

I use SCNTransaction to move game objects. More specifically, when the player taps somewhere on the screen, the object will move towards that destination. But sometimes the player may make a wrong move, so I want to create a button which can terminate all SCNTransactions.
However, unlike SKAction, which can be terminated with a simple line - self.removeAllActions(), SCNTransaction cannot be terminated or even paused from the outside according to the Apple Developer Documentation. Even worse, I find that before the object reaches its destination, its position has already changed to the destination's position, so I cannot simply use another SCNTransaction to counteract the ongoing one after knowing the object's current position.
Can anybody give me some hints? Thanks a lot.
SCNTransaction and its animation principles follow the one of Core Animation and CATransaction. To stop an animation you will have to set the model value to the current presentation value. For instance:
node.position = node.presentation.position
But if you are familiar with SKAction and would like to implement the same logic in your SceneKit app, you might want to have a look at SCNAction. They work identically.

How can I create a pop-up window using Cocos2d, SpriteBuilder and Objective-c?

So I'm trying to do exactly this:
http://blog.typpz.com/2013/12/09/ios-sdk-create-a-pop-up-window/
But since I am not using SpriteKit i can't use this exact method.
I imagine that there should be a way to create this same pop up window effect using sprite builders layer option maybe? Then animating it using some of the CCAction methods that exist. Im not sure though and don't really know how to go about figuring out.
Any help is appreciated.
A simple way to do this would be to create a CCLayer, as you said, and animate it.
Once you've created a CCLayer to the size of the "popup" you want, and then added whatever you want to put in it, you can then start animating it.
If you want to get a similar effect to the animation in the tutorial you linked, the best way would be to use a combination of CCActionFadeIn and CCActionScaleTo. Conveniently, Spritebuilder's animation set has both of these for use, and you can easily set up an keyframe animation from within Spritebuilder without too much code. (Make sure to name the animation sequence to something you can easily remember since you'll need to refer back to it when you start coding - I'd call it "PopupAnimation", or something like that.)
Once you've finished doing that, all you have to do is call the animation from your code. For example, if I have a CCButton whose selector is "showPopup", I would do:
func showPopup() {
self.animationManager.runAnimationsForSequenceNamed("PopupAnimation")
}
Assuming you've done everything right, the popup will now appear! But now you're stuck with the popup on the screen, and with no way out.
To fix this, make another animation sequence (I'll call this "RemovePopup") which will remove the popup from the screen. Add a button to your CCLayer, and set its selector to "hidePopup". From your code, you can then run:
func hidePopup() {
self.animationManager.runAnimationsForSequenceNamed("RemovePopup")
}
And now you have a "popup" window that you can animate!

iOS - limit on UIView animate?

So I'm making a simple trivia game and I have a timerView that shrinks as time passes. When the user selects an answer, it needs to stop shrinking immediately - it must be very responsive. I give the user 10 seconds per question. Originally I would animate 10 times (with a duration of 1.0f), calling the next "segment" of animation in the completion block of the previous animation. In the completion block I would check to see if the user has tapped an answer, and if so I don't continue the chain. That solution works fine except that it's not very responsive because it's on a per second basis-- user taps an answer at the start of the second segment and the bar has a noticeable continuation.
My solution to THAT problem was to instead have 1000 animation calls with a duration of 0.01f. After doing that, the responsiveness was on point - the view stops animating as soon as I tap an answer -- the issue though, is that it's not actually 10 seconds, it takes more like 20.
So question number 1: what's the smallest time interval animateWithDuration can actually process properly?
Question number 2: is there a better way to accomplish what I'm trying to do accomplish?
ill answer question two: yes there definitely is a better way, have a look at CADisplayLink
use it to shrink your view a little bit each frame, and end the display link when you need to
the most responsive way is: the user taps an answer, you response in the touch callback, remove animations. you can remove animations by CALayer's removeAllAnimations method
Another way to do it is to set the view to shrinking using a single animation with linear timing, and then set the speed of the view's layer to 0 to pause the animation. When you set the speed on the layer to 0 the animation pauses instantly.
This works because under the covers, UIView animation actually creates and installs CAAnimation objects on the view's layers. It's possible to pause and continue an in-flight UIView animation just like you can a CAAnimation.
I have a project called KeyframeViewAnimations (link) on github that allows you to pause, continue, or "scrub" UIView and CAAnimations back and forth with a slider. You could use that technique. The tricky bit will be figuring out how far along the animation is.

Animation end callback after adding points

My chart is adding points to its series in certain interval using addPoint(). I've set its animation duration via chart.animation.duration - is there any way of calling my custom callback after animation is completed? I want to make it look more "live". I know about events.redraw(), however this is being fired on the beginning of the animation.
You can also catch redraw function (api.highcharts.com/highstock#chart.events.redraw) and use setTimeout() which will have the same time as animation time.

Resources