Last active
August 29, 2015 14:20
-
-
Save kvnsmth/b5249120cd686aa44952 to your computer and use it in GitHub Desktop.
Quick hack to animate launch xib on launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
self.window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
var showOverlay = true // whatever you want | |
if showOverlay { | |
LaunchOverlayWindow.register(self.window!, duration: nil) { (overlayWindow) in | |
overlayWindow.transform = CGAffineTransformMakeScale(6.0, 6.0) | |
overlayWindow.alpha = 0.0 | |
} | |
} | |
self.window!.makeKeyAndVisible() | |
return true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class LaunchOverlayWindow: UIWindow { | |
static func register(appWindow: UIWindow, duration: NSTimeInterval?, effect: ((UIWindow) -> Void)?) { | |
var notificationIdentifer: AnyObject! | |
notificationIdentifer = NSNotificationCenter.defaultCenter().addObserverForName( | |
UIApplicationDidFinishLaunchingNotification, object: nil, queue: nil) { (notification) -> Void in | |
let objects = NSBundle.mainBundle().loadNibNamed("LaunchScreen", owner: self, options: nil) | |
if let view = objects[0] as? UIView { | |
let overlayWindow = LaunchOverlayWindow(frame: appWindow.bounds) | |
overlayWindow.addSubview(view) | |
overlayWindow.setTranslatesAutoresizingMaskIntoConstraints(false) | |
view.setTranslatesAutoresizingMaskIntoConstraints(false) | |
let viewBinding = ["subview": view] | |
overlayWindow.addConstraints( | |
NSLayoutConstraint.constraintsWithVisualFormat( | |
"V:|[subview]|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewBinding) | |
+ | |
NSLayoutConstraint.constraintsWithVisualFormat( | |
"H:|[subview]|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewBinding) | |
) | |
overlayWindow.makeKeyAndVisible() | |
UIView.animateWithDuration(duration ?? 0.5, animations: { () -> Void in | |
if let effect = effect { | |
effect(overlayWindow) | |
} else { | |
overlayWindow.alpha = 0.0 | |
} | |
}, completion: { (finished) -> Void in | |
appWindow.makeKeyAndVisible() | |
overlayWindow.removeFromSuperview() | |
NSNotificationCenter.defaultCenter().removeObserver(notificationIdentifer) | |
}) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment