2

Simple sin wave CGPath.

When added to layer flickering with black color, video:

https://gfycat.com/PaleIllAustraliansilkyterrier

Photo(it appears like this for milliseconds):

enter image description here

shapeLayer.lineWidth = 1
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = UIColor.white.cgColor

I remember that experienced something like this couple of years ago and make some workaround, but now I can't find exact project.

I'm already checked that width of view can be divided by length of wave, but no luck.

Some community thoughts? Have you ever experienced this?

1 Answers1

3

The flickering comes probably from setting the fill color. You should set this color to either the background color or (better) nil which avoids filling. Clear color and no color are not the same.

clemens
  • 16,716
  • 11
  • 50
  • 65
  • Setting to nil makes zero-effect. If I comment it, it is filling with black. – lenyapugachev Jan 19 '18 at 08:35
  • What is the background color from the shape layer? Would you please insert a code example for the animation and the complete layer configuration? – clemens Jan 19 '18 at 08:38
  • This is the point - as a background there can be a camera view. Code you can find here: https://github.com/soggybag/Sine-Wave/blob/master/Sine%20Wave/SineWaveView.swift, drawSineWaves function. – lenyapugachev Jan 19 '18 at 08:49
  • Unfortunately, your code has some dependencies and replies to a previous Swift version, so can't get it run quickly. However, I would highly recommend you to animate the path with a `CABasicAnimation` or `CAKeyFrameAnimation`. This will give you a better performance and will probably avoid the flickering. – clemens Jan 19 '18 at 09:21
  • OK, I've just put `sine.shapeLayer.fillColor = nil` in top of `viewDidLoad` and it stop to flicker. – lenyapugachev Jan 19 '18 at 11:18