Turn off effect

When I press power to turn off, I want to have effect that is fading out. Same goes when I turn on on power button in app. here is a link of app power button so you dont think about other power button.

How is this done with switch?