Skip to content

Instantly share code, notes, and snippets.

@aral
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aral/5e15df37ca3ad5a6d8ea to your computer and use it in GitHub Desktop.
Save aral/5e15df37ca3ad5a6d8ea to your computer and use it in GitHub Desktop.
Applying CATransitions — won’t work with vibrancy
//
// MainWindowController.swift
// Heartbeat
//
// Created by Aral Balkan on 07/02/2015.
// Copyright (c) 2015 Ind.ie.
// Released under the MIT license.
//
import Cocoa
class MainWindowController: NSWindowController {
override func windowDidLoad()
{
super.windowDidLoad()
NSNotificationCenter.defaultCenter().when(youGet: "FadeOutMainWindow", call: "fadeOutMainWindow:", on: self)
}
func fadeOutMainWindow(notification:NSNotification)
{
println("Fade out main window notification received from Main Window Controller.")
showDisabled()
}
func showDisabled()
{
//
// With thanks to Cocoa With Love / Matt Gallagher (http://www.cocoawithlove.com/2011/05/presenting-mac-dialog-sheet-with-visual.html)
//
// Don’t forget to set self.view.layerUsesCoreImageFilters = true on the view
println("Showing main window as disabled…")
let animation:CATransition = CATransition()
animation.type = kCATransitionFade
if let window = self.window
{
if let layer = window.contentView.layer?
{
layer.addAnimation(animation, forKey: "layerAnimation")
if let bounds = window.contentView.bounds
{
let blankingView = NSView(frame: bounds)
window.contentView.addSubview(blankingView)
let exposureFilter = CIFilter(name: "CIExposureAdjust")
exposureFilter.setDefaults()
exposureFilter.setValue(-1.25, forKey: "inputEV")
let saturationFilter = CIFilter(name: "CIColorControls")
saturationFilter.setDefaults()
saturationFilter.setValue(0.35, forKey: "inputSaturation")
let gloomFilter = CIFilter(name: "CIGloom")
gloomFilter.setDefaults()
gloomFilter.setValue(0.75, forKey: "inputIntensity")
if let blankingViewLayer = blankingView.layer
{
blankingViewLayer.backgroundFilters = [exposureFilter, saturationFilter, gloomFilter]
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment