Skip to content

Instantly share code, notes, and snippets.

@maxcampolo
Created January 11, 2016 19:36
Show Gist options
  • Save maxcampolo/557744a5e38421d17d7f to your computer and use it in GitHub Desktop.
Save maxcampolo/557744a5e38421d17d7f to your computer and use it in GitHub Desktop.
Animate the application status bar
func animateStatusBarHidden(hidden: Bool) {
let key = NSString(data: NSData(bytes: [0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x61, 0x72] as [CUnsignedChar], length: 9), encoding: NSASCIIStringEncoding)
let object = UIApplication.sharedApplication()
var statusBar: UIView?
if let mKey = key as? String {
if object.respondsToSelector(NSSelectorFromString(mKey)) {
statusBar = object.valueForKey(mKey) as? UIView
}
}
if let mStatusBar = statusBar {
if hidden {
UIView.animateWithDuration(0.2, animations: { () -> Void in
mStatusBar.transform = CGAffineTransformMakeTranslation(0.0, -20)
})
} else {
UIView.animateWithDuration(0.2, animations: { () -> Void in
mStatusBar.transform = CGAffineTransformMakeTranslation(0.0, 0.0)
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment