Skip to content

Commit

Permalink
Merge pull request #2 from eduardourso/feature/update-for-xcode8
Browse files Browse the repository at this point in the history
Swift 3 support
  • Loading branch information
eduardourso authored Aug 10, 2017
2 parents d9a28a3 + 6b817bb commit 446b689
Show file tree
Hide file tree
Showing 53 changed files with 858 additions and 2,663 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0
141 changes: 62 additions & 79 deletions Example/GIFGenerator.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
12 changes: 6 additions & 6 deletions Example/GIFGenerator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
38 changes: 29 additions & 9 deletions Example/GIFGenerator/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="MIE-xe-DLg">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="MIE-xe-DLg">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
Expand Down Expand Up @@ -30,45 +34,61 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="n8q-tK-TLU">
<rect key="frame" x="180" y="452" width="240" height="128"/>
<rect key="frame" x="67.5" y="519" width="240" height="128"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Fw5-7A-bTw">
<rect key="frame" x="14" y="49" width="109" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Gif from images"/>
<connections>
<action selector="gifFromImages:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="sUU-T3-Ziw"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JY2-OQ-JBs">
<rect key="frame" x="129" y="49" width="97" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Gif from video"/>
<connections>
<action selector="gifFromVideo:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="5U5-Qk-DtJ"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="Yn8-0N-Xdw"/>
<constraint firstAttribute="height" constant="128" id="b7T-eV-BWQ"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Result path" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9H4-Ez-jVk">
<rect key="frame" x="16" y="64" width="343" height="455"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="9H4-Ez-jVk" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="1n5-iA-E30"/>
<constraint firstAttribute="trailingMargin" secondItem="9H4-Ez-jVk" secondAttribute="trailing" id="7mN-YY-voi"/>
<constraint firstItem="n8q-tK-TLU" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="9ak-VK-cTb"/>
<constraint firstAttribute="bottom" secondItem="n8q-tK-TLU" secondAttribute="bottom" constant="20" symbolic="YES" id="ECx-mq-VDq"/>
<constraint firstItem="n8q-tK-TLU" firstAttribute="top" secondItem="9H4-Ez-jVk" secondAttribute="bottom" id="Mjy-j6-Jzz"/>
<constraint firstItem="n8q-tK-TLU" firstAttribute="top" secondItem="9H4-Ez-jVk" secondAttribute="bottom" id="dKJ-Fn-Aw6"/>
<constraint firstItem="9H4-Ez-jVk" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" id="yLr-01-hHA"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="Hfg-49-FN3"/>
<connections>
<outlet property="resultLabel" destination="9H4-Ez-jVk" id="RF1-26-hxP"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="638" y="192"/>
<point key="canvasLocation" x="637.60000000000002" y="191.1544227886057"/>
</scene>
</scenes>
</document>
48 changes: 21 additions & 27 deletions Example/GIFGenerator/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,47 @@

import UIKit
import GIFGenerator
import FLAnimatedImage

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

let imageView = FLAnimatedImageView()
@IBOutlet weak var resultLabel: UILabel!

let gifGenerator = GifGenerator()
private let imageView = UIImageView()

let images2:[UIImage] = [UIImage(named: "bart1.jpg")!, UIImage(named: "bart2.jpg")!, UIImage(named: "bart3.jpg")!, UIImage(named: "bart4.jpg")!, UIImage(named: "bart5.jpg")!]
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]

@IBAction func gifFromImages(sender: AnyObject) {
@IBAction func gifFromImages(_ sender: AnyObject) {
self.generateAnimatedImage(images2)
}

@IBAction func gifFromVideo(sender: AnyObject) {
@IBAction func gifFromVideo(_ sender: AnyObject) {
self.generateAnimatedGifFromVideo()
}

override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(self.imageView)
}

func generateAnimatedImage(imageArray: [UIImage]) {

let documentsPath : String = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0]
let destinationPath :String = documentsPath.stringByAppendingString("/animated.gif")
func generateAnimatedImage(_ imageArray: [UIImage]) {

let destinationPath = documentsPath + "/imageAnimated.gif"

gifGenerator.generateGifFromImages(imagesArray: imageArray, frameDelay: 0.5, destinationURL: NSURL(fileURLWithPath: destinationPath), callback: { (data, error) -> () in
let image = FLAnimatedImage(animatedGIFData: data)
self.imageView.animatedImage = image
self.imageView.frame = CGRectMake(0, 0, image.size.width/2, image.size.height/2)
self.imageView.center = self.view.center
gifGenerator.generateGifFromImages(imagesArray: imageArray, frameDelay: 0.5, destinationURL: URL(fileURLWithPath: destinationPath), callback: { (data, error) -> () in
print("Gif generated under \(destinationPath)")
DispatchQueue.main.async {
self.resultLabel.text = "Gif generated under \(destinationPath)"
}
})
}

func generateAnimatedGifFromVideo() {

let destinationPath = documentsPath + "/videoAnimated.gif"

let documentsPath : String = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0]
let destinationPath :String = documentsPath.stringByAppendingString("/animated.gif")

if let url = NSBundle.mainBundle().URLForResource("myvideo", withExtension: "mp4"){
if let url = Bundle.main.url(forResource: "myvideo", withExtension: "mp4") {

gifGenerator.generateGifFromVideoURL(videoURL: url, framesInterval: 10, frameDelay: 0.2, destinationURL: NSURL(fileURLWithPath: destinationPath), callback: { (data, error) -> () in
if let image = FLAnimatedImage(animatedGIFData: data) {
self.imageView.animatedImage = image
self.imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height)
self.imageView.center = self.view.center
gifGenerator.generateGifFromVideoURL(videoURL: url, framesInterval: 10, frameDelay: 0.2, destinationURL: URL(fileURLWithPath: destinationPath), callback: { (data, error) -> () in
print("Gif generated under \(destinationPath)")
DispatchQueue.main.async {
self.resultLabel.text = "Gif generated under \(destinationPath)"
}
})
} else {
Expand Down
10 changes: 2 additions & 8 deletions Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target 'GIFGenerator_Example', :exclusive => true do
target 'GIFGenerator_Example' do
pod 'GIFGenerator', :path => '../'
pod 'FLAnimatedImage'
end

target 'GIFGenerator_Tests', :exclusive => true do
pod 'GIFGenerator', :path => '../'


end
16 changes: 16 additions & 0 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PODS:
- GIFGenerator (0.2.0)

DEPENDENCIES:
- GIFGenerator (from `../`)

EXTERNAL SOURCES:
GIFGenerator:
:path: ../

SPEC CHECKSUMS:
GIFGenerator: cc64975b1f6fdd9886a0259800d8b4d330781c4b

PODFILE CHECKSUM: a30bc838638cc1baff83cb7cc9587133b7db289a

COCOAPODS: 1.3.0
82 changes: 0 additions & 82 deletions Example/Pods/FLAnimatedImage/FLAnimatedImage/FLAnimatedImage.h

This file was deleted.

Loading

0 comments on commit 446b689

Please sign in to comment.