What is the default value of (NSTimeInterval)duration for UIModalTransitionStyleFlipHorizontal, which is related to -[UIViewController presentModalViewController:animated:]?
If you are asking what the default value of the duration is on an animation when you do not explicitly set it, the answer is provided in the framework headers:
* If the `duration' property of the animation is zero or negative it
* is given the default duration, either the value of the
* `animationDuration' transaction property or .25 seconds otherwise.
So, since you can't set the value on the method call, it should take a quarter second to execute the animation.
Related
I can use CAShapeLayer and UIBezierPath to draw the circle, I can also use this property CAShapeLayer.strokeEnd to control the progress. But the fast scrolling of path and time , I do not know how to implement.
Now I think the approach is to calculate the time difference between the two , and then use the time difference to circulation .
For example, The time difference between the two is 1000 seconds , should I have to set strokeEnd and the middle of the Label 1000 cycles ? Or that implement good results it ?
thanks in advance!
Note : StrokeEnd accepts value between 0 - 1
Lets Say,
See in your case circle represents the remaining time it will take to appear new feed. lets say 3PM.
so 3 PM will be your nextFeedTime = 3PM and,
you got this feed at 12PM so feedTime = 12PM.
So now you will have start and end value of feedTime=12PM - nextFeedTime=3PM
So feedTime is 0 for strokeEnd and nextFeedTime is 1 for StrokeEnd.
When you open app you will got currentTime which is initially initialised with feedTime and later it will be replaced all the time with current time stamp.
Lets assume currentTime is 1 PM.
Now we can calculate ratio to animate strockEnd property
strokeEnd = currentTime / nextFeedTime
and animate strokeEnd accordingly. hope this will helps you!
Question: The update(currentTime:) function in SKScene is called every frame with a currentTime argument. I'm wondering how to get the time from the same source update(currentTime:) uses without using the update function. I only found CFAbsoluteTimeGetCurrent() which is different.
Reason: To calculate timeSinceLastUpdate you need an instance variable called timeOfLastUpdate. To implement timeOfLastUpdate you need to set it to an arbitrary value before the first update which makes the first calculation of timeSinceLastUpdate incorrect. You could have a simple if statement to detect this or use optionals but that is an unneeded branch which could be avoided if I just set timeOfLastUpdate in didMoveToView(view:). And that is what I'm trying to do.
The first timeSinceLastUpdate will always be different from the rest. Typically one stores the absolute time from the previous update call and subtracts it from the current call's time to get a timeSinceLastUpdate. If the previous time doesn't exist because you're on the first pass through the render loop — it's set to zero or infinity or negative something or whatever sentinel value you initialized it to, just set your timeSinceLastUpdate to some nominal value for getting started. Something like your frame interval (16.67 ms if you're going for 60 fps) would make sense — you don't want game code that depends on that time interval to do something wild because you passed it zero or some wildly huge value.
In fact, it's not a bad idea to have logic for normalizing your timeSinceLastUpdate to something sane in the event that it gets foo large — say, because your user paused and resumed the game. If you have game entities (such as GameplayKit agents) whose movement follows some sort of position += velocity * timeSinceLastUpdate model, you want them to move by one frame's worth of time when you resume from a pause, not take a five-minute pause times velocity and jump to hyperspace.
If you initialize your previous time to zero, subtract, and normalize to your expected frame interval, you'll cover both the starting and unpausing cases with the same code.
You could always use coalesce:
let deltaTime = currentTime - (previousTime ?? currentTime).
On first loop, your deltaTime is 0 (Should be this) after that, it is the change
Of course previousTime must be an optional for this to work
I'm animating some particles and rather than have then just disappear at the end of their lifetime I'd like them to fade out.
I have a CAEmitterCell defined with a lifetime of 35.0. I don't want to just have the particle fade out over the full duration of the particle lifetime. I only want it to fade out at the end. Perhaps the last 2 or 3 seconds.
For the CAEmitterCell's color property, set the alpha value to lifetime * alphaSpeed (where alphaSpeed is -1.0/fadeOutDuration).
So for a lifetime of 35.0 and a fadeOutDuration of 2.0, alphaSpeed would be -0.5, and alpha would be 17.5.
There are a couple caveats:
This only works if your cells are supposed to start at full alpha.
You'll have to set CAEmitterCell's color property using a CGColorRef created with CGColorCreateCopyWithAlpha. Both UIColor and CGColorCreate clamp their values to a maximum of 1.0. For whatever reason, CGColorCreateCopyWithAlpha doesn't.
Just came across this in the docs which might point in the right direction:
name
The name of the cell.
#property(copy) NSString *name
Discussion
The cell name is used when constructing animation key paths that reference the cell. Defaults to nil.
For example, adding an animation to a cell’s enclosing layer with the a keypath such as emitterCells.myCellName.redRange would animate the redRange propery of the cell in the layer’s emitterCells array with the name myCellName.
Availability
Available in Mac OS X v10.6 and later.
Declared In
CAEmitterCell.h
I gather you still add the animation to the layer but with a key path that references a part of that layer - in this case the cell's property. Is there an alpha property exposed for cells?
I have a custom slider whose min and max values are 0 and 1 respectively.
I want to set the thumb at a particular duration(at 1s) of the file. How do I do that calculation? Currently, I'm multiplying the slider value with the total duration of file to get the desired position.
But, now depending on my preference, how do I set the thumb?
Please advise.
The easiest thing would be to set the max value of the slider to the length of your file. It's a settable property, so just
slider.maximumValue = fileDuration;
would work. Then, you can just set the value for however long into the file you want.
If you can't do that for other reasons, you need to normalize the position you want by the file length (that is, divide the position you want by the file duration to find the value):
slider.value = (desiredPosition / fileDuration);
Note that with this, if desiredPosition is the entire length of the file, you get 1 (the maximum value of the slider by default)
For my understanding, beginTime can be used to say "hey, start at exactly 12:00 'o clock". But how would I tell this with an CFTimeInterval type? I thought that this one is nothing more than a kind of "float" value to specify seconds.
Or what else would be then the difference to the timeOffset property that is specified in CAMediaTiming protocol?
What I missed in the docs: beginTime is in "core animation absolute time" so you've to get the current time and specify your offset from that:
// Start in 5 seconds
theAnimation.beginTime = CACurrentMediaTime() + 5;
You first need to convert to the layer's timespace like so:
let currentLayerTime = myLayer.convertTime(CACurrentMediaTime(), from: nil)
Then you can set the beginTime relative to the layer's now time. For instance, to make an animation begin in 2s:
myAnimation.beginTime = currentLayerTime + 2
You'll also likely want to set the fillMode to .backwards, so that you can set the final property value before you add the animation:
myAnimation.fillMode = .backwards
myLayer.someProperty = someFinalValue
myLayer.addAnimation(myAnimation, forKey: "myAnimationName")
No, that is not what beginTime does. It specifies a relative start time from its parent animation (by default multiple animations in a group all fire at once).
From the documentation:
Specifies the begin time of the
receiver in relation to its parent
object, if applicable.
timeOffset causes it to start animating at the frame it would be at at the offSet time, and when it reaches the end it loops around. In other words, imagine A,B,C,D,E are frames of animation this is what happends in various cases if you set beginTime or timeOffset to a value equal to when you hit frame C in the normal case.
Normal |A->B->C->D->E
beginTime: | A->B->C->D->E
timeOffset: |C->D->E->A->B
I think the documentation of CAMediaTiming Protocol is very bad. Time Warp in Animation is a thorough explanation(re-documentation) of all properties of CAMediaTiming Protocol.