// Methods to adjust the keyboard
extension GiftEditorViewController {
func subscribeToKeyboardNotifications(){
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GiftEditorViewController.keyboardWillShow(_:)),
name: UIKeyboardWillShowNotification,
object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GiftEditorViewController.keyboardWillHide(_:)),
name: UIKeyboardWillHideNotification,
object: nil)
}
func unsubscribeFromKeyboardNotifications(){
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
func keyboardWillShow(notification: NSNotification){
if view.frame.origin.y >= 0 {
view.frame.origin.y -= getKeyboardHeight(notification)
}
}
func getKeyboardHeight(notification: NSNotification) -> CGFloat{
let userInfo = notification.userInfo
let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
return keyboardSize.CGRectValue().height
}
}
Share the GIF
@IBAction func shareGif(sender: AnyObject){
let url: NSURL = (self.gif?.url)!
let animatedGIF = NSData(contentsOfURL: url)!
let itemsToShare = [animatedGIF]
let activityVC = UIActivityViewController(activityItems: itemToShare, applicationActivities: nil)
activityVC.completionWithItemsHandler = {(activity, completed, items, error) in
if(completed){
self.navigationController?.popToRootViewControllerAnimated(true)
}
}
navigationController?.presentViewController(activityVC, animated: true, completion: nil)
}
Create an Action Sheet
@IBAction func presentVideoOptions(){
if !UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
//launchPhotoLibrary()
} else {
let newGifActionSheet = UIAlertController(title: "Create new GIF", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
let recordVideo = UIAlertAction(title: "Record a Video", style: UIAlertActionStyle.Default, handler: {
(UIAlertAction) in self.launchVideoCamera()
})
}
}