3

I need to add a background where random clouds comes from the sides. This effect need to be almost in every screen of the app. I tried using animateWithDuration with UIImageViews but it consumes a lot of battery, and when I am on some screens with other extra animations, this animations look jerky.

Also tried using .gif and videos as background:

Video as background

But they are to heavy, since it has to be a long video in order to make it look like the clouds appears in random intervals. And also consumes a lot of resources.

Are there other ways to make this effect, like a lightweight animation technique?

Oscar J. Irun
  • 455
  • 5
  • 17
  • take a look at [this library](https://github.com/Boris-Em/NightView) , it doesn't add clouds but stars :D you can take a look at how it is structured in order to get an idea – LS_ Jul 14 '16 at 15:07
  • A high performance implementation of animation can be found at this answer: http://stackoverflow.com/a/21079559/763355 – MoDJ Aug 15 '16 at 18:31

1 Answers1

0

I imagine your best bet would be to use a CALayer on your UIViews, it should be more lightweight than the UIImage solution.

George Brown
  • 1,134
  • 10
  • 25
  • I tried it just now, unfortunately, I have the same results. And one problem with this solution is that CALayer can't be rendered offscreen (To make the clouds enter from the sides) – Oscar J. Irun Jul 14 '16 at 15:52
  • How are you drawing the clouds? You create the clouds as sublayers using images, and then just move them about. – George Brown Jul 14 '16 at 16:09
  • I was creating a CALayer setting its `content` with a `[UIImage imageNamed:@"cloud"].CGImage`. I found this too http://stackoverflow.com/questions/4686873/ios-should-i-add-uiviews-or-calayers-for-animation. It says there is almost no difference between both approachs :( – Oscar J. Irun Jul 14 '16 at 16:56
  • I wouldn't have thought it to be that intensive, are your cloud images optimised for the resolution you're using? – George Brown Jul 14 '16 at 17:28
  • In my case, I only have 8 clouds. And when any of the clouds dissapears from screen it should start the animation again. And yes, they are optimized for the resolution. – Oscar J. Irun Jul 14 '16 at 17:39