import Foundation
import UIKit
import MobileCoreServices
// Regift constants
let frameCount = 16
let delayTime: Float = 0.2
let loopCount = 0 // 0 means loop forever
extension UIViewController: UIImagePickerDelegate, UINavigationControllerDelegate {
@IBAction func launchVideoCamera(sender: AnyObject){
let recordVideoController = UIImagePickerController()
recordVideoController.sourceType = UIImagePickerControllerSourceType.launchVideoCamera
recordVideoController.mediaTypes = [kUTTypeMovie as String]
recordVideoController.allowsEditing = false
recordVideoController.delegate = self
presentViewController(recordVideoController, animated: true, completion: nil)
}
public func imagePickereController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){
let mediaType = info[UIImagePickerControllerMediaType] as! String
if mediaType == kUTTypeMovie as String {
let videoURL = info[UIImagePickerControllerMediaURL] as! NSURL
dismissViewControllerAnimated(true, completion: nil)
UISaveVideoAtPathToSavedPhotosAlbum(videoURL.path!, nil, nil, nil)
}
}
public func imagePickerControllerDidCancel(picker: UIImagePickerController){
dismissViewControllerAnimated(true, completion: nil)
}
func convertVideoToGIF(videoURL: NSURL){
let regift = Regift(sourceFileURL: videoURL, frameCount: frameCount, delayTime: delayTime, loopCount: loopCount)
}
}
#import <UIKit/UIKit.h> #import "Gif.h" @interface GifEditorViewController : UIViewController<UITextFiledDelegate> @property (nonatomic) Gif *gif; @property (weak, nonatomic) IBOutlet UIImageView *gifImageView; @end
Rewriting the Gif Class
@interface Gif : NSObject <NSCoding> @property (nonatomic) NSURL *url; @property (nonatomic) NSString *caption; @property (nonatomic) UIImage *gifImage; @property (nonatomic) NSURL *videoURL; @property (nonatomic) NSData *gifData; -(instancetype)initWithGifUrl: (NSURL*)url videoURL:(NSURL*)videoURL caption:(NSString*)caption; -(instancetype)initWithName:(NSString*)name; @end