Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa - Fade between two NSImage's?

I have a menu with an NSImage showing some information, and when it gets updated I would like the new (updated) image to fade in. I know it is easy on the iPhone, but is this possible in OS X ?

like image 237
Nippysaurus Avatar asked Dec 16 '22 16:12

Nippysaurus


2 Answers

You can try using this. It was written in Swift 4

 let transition = CATransition() //create transition
 transition.duration = 4 //set duration time in seconds
 transition.type = .fade //animation type
 transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
 self.imageView.layer?.add(transition, forKey: nil) //add animation to your imageView's layer
 self.imageView.image = NSImage(named: "test_image") //set the image
like image 117
Silviu St Avatar answered Jan 08 '23 23:01

Silviu St


I think that one of the most valuable example is ImageTransition. It's easy to understand at least for me, coming from the iOS world. http://developer.apple.com/library/mac/samplecode/ImageTransition/ImageTransition.zip

Hope it helps, Paolo

like image 31
SlowTree Avatar answered Jan 09 '23 01:01

SlowTree