Comments (8)
hmmm, there is still an issue.
I have a timeline animation (with self) and also another single animation (also with self)
timeline.add(Kinetic.fromTo(self, duration: 0.5, from:[.Translate(0,bounds.height)], to:[.Translate(0,0)]).ease(Easing.outSine),position: 0)
I made a function to be called before the view disappears, to call timeline.kill()
.
But that's not enough, I also have to call Kinetic.killTweensOf(self)
to really free the reference.
from kinetic.
The engine does store a strong reference to each target so it can cache Tween instances associated with it for returning later via getTweensOf
and killTweensOf
. There could be two solutions: your option where I add a killOnCompletion()
method similar to CAAnimation's removedOnCompletion
, or always remove them from the cache once all tween animations associated with that object have completed, which may be the cleanest solution.
from kinetic.
I prefer the second one, too. I guess the vast majority of calls are one offs.
One concern remains though, how would the engine handle it if the Tween is part of a timeline?
Maybe there is keepReference()
switch that's automatically added instead of the killOnCompletion()
approach.
Or if someone stores the return value and tries to trigger the play handle after the animation has finished? I have no problem if that's explicitly not possible as long as it is mentioned in the docs.
from kinetic.
I opted for the automatic approach for removing tweens from the cache when they have completed their animation, which is in this commit if you want to review: 5ed0e31
I verified that the tweens are removed from the internal cache by calling Kinetic.getTweensOf(target)
multiple times during a timeline animation which should be nil
when the animation completes and it's the only animator for the target. If the animation is played afterwards, the tweens are re-added back into the cache and removed upon completion again whenever kill()
is called.
If the tween is part of a timeline, the timeline instance always retains the child tweens, so there's no need to manually store a reference to a tween within a timeline. However, if you want to be able to replay a single Tween instance that's not part of a Timeline, a strong reference will be needed since the object will be deallocated when removed from the internal cache when completed.
from kinetic.
Great! Good solve!
Just to be safe, if I call timeline.kill() all elements get killed of it as well, right?
from kinetic.
@markuswinkler Can you provide more code on how you're implementing this animation where you're noticing the issue? Looks like you're adding the animation code directly within a UIView subclass (self
is used when adding tweens).
I did a test locally trying to reproduce how you have your animation setup and didn't notice any memory leaks. Here's my simple UIView subclass where the animation is setup:
class TestView: UIView {
var timeline = Timeline()
func animate() {
timeline.add(Kinetic.fromTo(self, duration: 0.5, from:[.Translate(0, bounds.height)], to:[.Translate(0,0)]).ease(Easing.outSine),position: 0)
timeline.play()
}
func reset() {
timeline.kill()
}
}
And the simple view lifecycle methods in the controller, where testView
is a strong reference property:
override func viewDidLoad() {
super.viewDidLoad()
testView = TestView(frame: CGRect(origin: CGPoint(x: 100, y: 200), size: CGSize(width: 100, height: 100)))
testView.backgroundColor = UIColor.greenColor()
view.addSubview(testView)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
testView.animate()
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
testView.reset()
}
from kinetic.
Just ran your test, can confirm it works now.
You don't even have to call .kill anymore.
If I add the following code to animate in TestView:
timeline.onComplete { [weak self](Animation) in
self?.removeFromSuperview()
}
and
deinit {
print("DEINIT: testview")
}
deinit is called when the animation finishes.
When I posted the bug initially deinit wasn't called after completion.
Got probably solved with one of the other optimizations you put in.
from kinetic.
Sweet, I like those kind of issues. :)
from kinetic.
Related Issues (20)
- Bug: .RotateY only works with .to, not .from HOT 2
- Bug: animation doesn't execute if not called from main thread HOT 7
- Please add @discardableResult to key functions in the swift 3 branch HOT 2
- Feature Request: Swift 3 HOT 2
- onComplete doesn't get called when tween inside timeline HOT 6
- bezierPath? HOT 4
- Cannot animate SKNode objects. HOT 1
- Memory leak in Tween HOT 2
- User interaction while animating HOT 1
- it stop to work with Swift 4.1 HOT 1
- Interpolator issue HOT 1
- Is there a way to say if element is currently tweening HOT 1
- UIViews inside ScrollView animated HOT 1
- Can we tween a tableview? HOT 2
- How can I install it manually HOT 1
- EasingType - Bounce? How to use this? HOT 3
- Getting error: Dependency "Kinetic" has no shared framework schemes with Carthage
- ZoomIn and ZoomOut option?
- Tween not working on CGAffineTransform
- Not working on iOS 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kinetic.