2

I need to set my view's background in gradient color and it must change their colors gradually with respect to time link in the following video.

sample video

I have tried some layer animation but it is not worthy as we can't change the color of layer gradually. Can anyone tell me how to do this stuff. Thanks in advance.

surendher
  • 1,374
  • 3
  • 26
  • 52
  • 1
    You could use the technique here http://stackoverflow.com/questions/844710/make-background-of-uiview-a-gradient-without-sub-classing to get a UIColor with the gradient and update it with a timer (maybe reusing the CGColorSpace and CGContextRef rather than regenerating them each time, and pass in appropriate values from whatever's implementing the clock – Rich Tolley Feb 05 '13 at 17:56
  • But i want the color to change gradually with time. How is it possible – surendher Feb 07 '13 at 09:39

1 Answers1

0

You're already updating the UI at consistent intervals (the clock hands). Just update the gradient at those intervals and add a crossfade to the background view's layer.

CATransition *transition = [CATransition animation];
transition.duration = duration;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
transition.type = kCATransitionFade;
[backgroundView.layer addAnimation:transition forKey:nil];

The duration value would be the time in between updates to the UI.

Ash Furrow
  • 12,391
  • 3
  • 57
  • 92
  • Please Excuse me, i didn't understand what you're saying. I am really a rookie in this concept. Please explain me in detail – surendher Feb 07 '13 at 10:11
  • If you have a timer that's already updating the view (the second hand of the clock), you can update the background gradient at the same time. If you don't know where to begin on that, then we can help you. Ask another SO question about `NSTimer`. – Ash Furrow Feb 07 '13 at 11:04