Animations set in collectionView keep reloading - swift

I have a collectionView and each cell has a graph that animates once the collectionView loads. The animation is based on CAShapeLayer animation and the value is being passed from the collectionView.
The animation works somewhat fine for most cells. The two things that I am running into are:
1) When I scroll down and new cells appear, the animation for those newly appeared cells begin, but the progressLabel only appears when the animation is finished (which is odd).
2) When I scroll back to top, cells that previously already animated will partially animate again.
Is there a way to have all cells animate once the view controller loads and prevent any additional animations?
This is a follow-up to my previous question, which has the code I am using for this: Setting toValue for CAShapeLayer animation from UICollectionView cellForItemAt indexPath

Related

Change UITableView contentOffset while user is scrolling

I am changing content offset programically with:
tableView.contentOffset.y += 100
This works well when the tableview is not scrolling at all. But when there is a scrolling animation, or when user is scrolling then it is reverted.
I've noticed UICollectionView allows you to keep the animation, and user interaction and move the scroll view with contentOffset, but I am not able to use UICollectionView.
Any ideas how can I change tableview's contentOffset even during user scrolling?
Swift playground:
https://gist.github.com/patryk-sredzinski/8f7111acbe7b1a65406463f70866b0b9.js
(inserting rows on top, changing the offset to keep user at the same cells, but whenever user scrolls on tableview, these offset changes breaks)

Corner Radius does not working in UICollectionView until it gets scroll

I used a vertical scroll direction collection view inside a tableViewcell.
Everything is working fine except the round corners. They come into effective when I scroll the collection view to and forth (Only starting and ending rows only)
I tried adding round corners to contentView and to the customer view Container added to contentView.
I tried to add code in willDisplay as well as inside the cell itself. I also called layoutIfNeeded() but nothing work.
Any one can please suggest what am I doing wrong?
Note: I can't put corner radius in awakeFromNib method as the shape of cell is being decided dynamically.

Show/Hide subview from UIStackView inside UITableViewCell is having animation

I have a UIImageView inside of UIStackView in UITableViewCell. Based on some parameters i want to show/hide that imageView.
I do this in cellForItemAt method by setting isHidden parameter on imageView. This works just fine for all but one case. When i do pull to refresh (so reloadData()) on tableView this imageView appears with animation (it slides from left). Is there any way to disable this?
Update:
I noticed that this happens because i have UISearchController in navigationItem.searchController. Not sure if anyone else had this issue before?

Animation stops when cell disappear and not resume when appear again

I am having simple animation (actually two of them, but will show only one for simplicity of an example) which continuously fades in, and fades out a label. So, when I scroll the tableview in such a way that some animated cells disappear, and then scroll back, those cells aren't animated anymore.
Here is the animation:
UIView.animateKeyframesWithDuration(
0.5,
delay: 0.0,
options: [.Repeat, .Autoreverse, .AllowUserInteraction],
animations: {
self.stateLabel.alpha = 0.5
}, completion: nil)
I start this animation in method called setup() which is an instance method of my custom cell class (which inherits from UITableViewCell). As I said, there is another animation which behaves the same, and it shakes the imageview, so I am positive that this is not related to fading kind of an animation.
I invoke setup() method in cellForRowAtIndexPath method after dequeuing.
What I have tried is to run this setup() method in willDisplayCell method, but the result is the same (I am not dequeueing cell in this method of course).
Also I tried with break points, and the animation code is executed. Just, animation doesn't start when cell re-appears. So the question is, how to restart / continue with animation when cell appears again?
Well the problem is not resetting the alpha value of the UI element after displaying it. Because UITableView would restore but not recreate the cell if dequeueReusableCellWithIdentifier function is being used. Thus resetting the alpha value on cellForRowAtIndexPath and animating the view in willDisplayCell would solve the problem you were facing.

Run method on first set of UICollectionViewCells, but no on subsequent cells

I have a UICollectionView containing cells that are showing a preview of the camera. I've added a black UIView as a "veil" on top of the cell through storyboard.
When the camera previews begin, I animate the veil UIViews of all cells from an veil.alpha = 1 to veil.alpha = 0. This smooths out the effect of the camera preview starting.
However, this means that when a cell is initialized, but not added to the view, I have to wait until it's added to the view before I can remove the veil UIView. If I attempt beforehand, the veil UIView is nil.
The result is that as I'm scrolling, I catch a glimpse of the veil being animated away for any cells that have not been initialized beforehand.
A simple solution would be to check something like:
"If this cell is being scrolled into visibility, and the camera is already running, before the cell is visible, just set the
veil.alpha = 0."
However, I'm not sure where in the cell/controller lifecycle to put this.
I've tried setting this in prepareForReuse(), layoutSubviews() in the cell, and in cellForItemAtIndexPath in containing controller. All three of those methods cause the veils of the initial visible cells to immediately jump to veil.alpha = 0 without the animation.
Thank you.