Skip to content

Instantly share code, notes, and snippets.

@celian-m
Created June 17, 2016 08:24
Show Gist options
  • Save celian-m/9002fe12009598c2e1ba03c9edf58414 to your computer and use it in GitHub Desktop.
Save celian-m/9002fe12009598c2e1ba03c9edf58414 to your computer and use it in GitHub Desktop.
Super View controller for iOS swift apps
//
// SuperViewController.swift
// Mouce
//
// Created by Célian MOUTAFIS on 15/06/2016.
// Copyright © 2016 Célian MOUTAFIS. All rights reserved.
//
import Foundation
import UIKit
public class SuperViewController : UIViewController {
override public func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.Default
}
override public func prefersStatusBarHidden() -> Bool {
return false
}
override public func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillShow), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillHide), name: UIKeyboardWillHideNotification, object: nil)
}
override public func viewWillDisappear(animated: Bool) {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
super.viewWillDisappear(animated)
}
var appDelegate: AppDelegate {
get {return UIApplication.sharedApplication().delegate! as! AppDelegate}
}
func keyboardWillShow(notification : NSNotification){
let frame : CGRect = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as? NSValue)!.CGRectValue()
self.keyboardWillChangeFrame(frame, notification: notification)
}
func keyboardWillHide(notification : NSNotification){
let frame : CGRect = CGRectZero
self.keyboardWillChangeFrame(frame, notification: notification)
}
func keyboardWillChangeFrame(frame : CGRect, notification : NSNotification){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment