Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion to Swift 4 #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
409 changes: 409 additions & 0 deletions Animoji.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Animoji/Animoji-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "AVTAvatarView.h"
#import "AVTPuppet.h"
#import "AVTPuppetView.h"
47 changes: 47 additions & 0 deletions Animoji/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// AppDelegate.swift
// Animoji
//
// Created by Daniel Illescas Romero on 25/12/2017.
// Copyright © 2017 Daniel Illescas Romero. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = UINavigationController(rootViewController: ViewController())
self.window?.makeKeyAndVisible()
return true
}

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 invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

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) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

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) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions Animoji/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
24 changes: 24 additions & 0 deletions Animoji/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
14 changes: 8 additions & 6 deletions SBSAnimoji/Supporting files/Info.plist → Animoji/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>Tracking your face</string>
<key>NSMicrophoneUsageDescription</key>
<string>Recording your voice</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Saving your video</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand All @@ -43,5 +39,11 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSCameraUsageDescription</key>
<string>Tracking your face</string>
<key>NSMicrophoneUsageDescription</key>
<string>Recording your voice</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Saving your video</string>
</dict>
</plist>
135 changes: 135 additions & 0 deletions Animoji/Model/MainView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//
// MainView.swift
// Animoji
//
// Created by Daniel Illescas Romero on 25/12/2017.
// Copyright © 2017 Daniel Illescas Romero. All rights reserved.
//

import UIKit

@objc class MainView: UIView {

var puppetView = SBSPuppetView()
var thumbnailsCollectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewLayout())
var recordButton = UIButton(type: .system)
var shareButton = UIButton(type: .system)
var deleteButton = UIButton(type: .system)
var previewButton = UIButton(type: .system)
var activityIndicatorView = UIActivityIndicatorView()
var durationLabel = UILabel()
var puppetViewSeparatorView = UIView()

override init(frame: CGRect) {
super.init(frame: frame)
self.setupView()
self.setupLayout()
}

func setupView() {

self.backgroundColor = .white

self.puppetView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(self.puppetView)

self.puppetViewSeparatorView.translatesAutoresizingMaskIntoConstraints = false
self.puppetViewSeparatorView.backgroundColor = UIColor(red: 224.0/255.0, green: 224.0/255.0, blue: 224.0/255.0, alpha: 1.0)
self.addSubview(self.puppetViewSeparatorView)

let collectionViewLayout = UICollectionViewFlowLayout()
collectionViewLayout.scrollDirection = .vertical
collectionViewLayout.minimumInteritemSpacing = 14
collectionViewLayout.minimumLineSpacing = 10

self.thumbnailsCollectionView.setCollectionViewLayout(collectionViewLayout, animated: true)
self.thumbnailsCollectionView.translatesAutoresizingMaskIntoConstraints = false
self.thumbnailsCollectionView.backgroundColor = .white
self.thumbnailsCollectionView.contentInset = UIEdgeInsets(top: 15, left: 7, bottom: 15, right: 7)
self.thumbnailsCollectionView.showsHorizontalScrollIndicator = false
self.addSubview(self.thumbnailsCollectionView)

self.durationLabel.translatesAutoresizingMaskIntoConstraints = false
self.durationLabel.textAlignment = .right
self.durationLabel.font = .systemFont(ofSize: 14, weight: .medium)
self.durationLabel.isHidden = true
self.addSubview(self.durationLabel)

self.deleteButton.translatesAutoresizingMaskIntoConstraints = false
self.deleteButton.isHidden = true
self.deleteButton.setImage(#imageLiteral(resourceName: "delete"), for: .normal)
self.addSubview(self.deleteButton)

self.previewButton.translatesAutoresizingMaskIntoConstraints = false
self.previewButton.isHidden = true
self.previewButton.setImage(#imageLiteral(resourceName: "start-previewing"), for: .normal)
self.addSubview(self.previewButton)

self.recordButton.translatesAutoresizingMaskIntoConstraints = false
self.recordButton.setImage(#imageLiteral(resourceName: "start-recording"), for: .normal)
self.addSubview(self.recordButton)

self.shareButton.translatesAutoresizingMaskIntoConstraints = false
self.shareButton.isHidden = true
self.shareButton.setImage(#imageLiteral(resourceName: "share"), for: .normal)
self.addSubview(self.shareButton)

self.activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
self.activityIndicatorView.hidesWhenStopped = true
self.addSubview(self.activityIndicatorView)
}

func setupLayout() {

self.puppetView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
self.puppetView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
self.puppetView.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor).isActive = true
self.puppetView.heightAnchor.constraint(equalToConstant: 355).isActive = true

self.puppetViewSeparatorView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
self.puppetViewSeparatorView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
self.puppetViewSeparatorView.topAnchor.constraint(equalTo: self.puppetView.bottomAnchor).isActive = true
self.puppetViewSeparatorView.heightAnchor.constraint(equalToConstant: 2).isActive = true

self.thumbnailsCollectionView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
self.thumbnailsCollectionView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
self.thumbnailsCollectionView.topAnchor.constraint(equalTo: self.puppetViewSeparatorView.bottomAnchor).isActive = true
self.thumbnailsCollectionView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true

self.durationLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20).isActive = true
self.durationLabel.topAnchor.constraint(equalTo: self.puppetView.topAnchor, constant: 15).isActive = true

self.recordButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20).isActive = true
self.recordButton.bottomAnchor.constraint(equalTo: self.puppetView.bottomAnchor, constant: -20).isActive = true

self.shareButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20).isActive = true
self.shareButton.bottomAnchor.constraint(equalTo: self.puppetView.bottomAnchor, constant: -20).isActive = true

self.deleteButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20).isActive = true
self.deleteButton.topAnchor.constraint(equalTo: self.puppetView.topAnchor, constant: 15).isActive = true

self.previewButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20).isActive = true
self.previewButton.topAnchor.constraint(equalTo: self.deleteButton.bottomAnchor, constant: 15).isActive = true

self.activityIndicatorView.centerXAnchor.constraint(equalTo: self.shareButton.centerXAnchor).isActive = true
self.activityIndicatorView.centerYAnchor.constraint(equalTo: self.shareButton.centerYAnchor).isActive = true
}

override func layoutSubviews() {
super.layoutSubviews()

let itemsPerRow: CGFloat = 4
let collectionView = self.thumbnailsCollectionView
let contentInset = collectionView.contentInset

if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
let availableWidth = self.bounds.size.width - contentInset.left - contentInset.right - (itemsPerRow - 1) * flowLayout.minimumInteritemSpacing
let itemLength = floor(availableWidth / itemsPerRow)
flowLayout.itemSize = CGSize(width: itemLength, height: itemLength)
}
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
51 changes: 51 additions & 0 deletions Animoji/Model/PuppetThumbnailCollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// PuppetThumbnailCollectionViewCell.swift
// Animoji
//
// Created by Daniel Illescas Romero on 25/12/2017.
// Copyright © 2017 Daniel Illescas Romero. All rights reserved.
//

import UIKit

@objc class PuppetThumbnailCollectionViewCell: UICollectionViewCell, UICollectionViewDelegate {

var thumbnailImageView = UIImageView()
var selectionImageView = UIImageView()

override init(frame: CGRect) {
super.init(frame: CGRect.zero)
self.setupView()
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func setupView() {

self.backgroundColor = .white

self.thumbnailImageView.translatesAutoresizingMaskIntoConstraints = false
self.thumbnailImageView.contentMode = .scaleAspectFit
self.contentView.addSubview(self.thumbnailImageView)

self.selectionImageView.image = #imageLiteral(resourceName: "selection")
self.selectionImageView.translatesAutoresizingMaskIntoConstraints = false
self.selectionImageView.isHidden = true
self.contentView.addSubview(self.selectionImageView)
}

override func layoutSubviews() {
super.layoutSubviews()
let thumbnailMargins = UIEdgeInsetsMake(7, 7, 7, 7)
self.thumbnailImageView.frame = UIEdgeInsetsInsetRect(self.contentView.bounds, thumbnailMargins)
self.selectionImageView.frame = self.contentView.bounds
}

override var isSelected: Bool {
didSet {
self.selectionImageView.isHidden = !isSelected
}
}
}
67 changes: 67 additions & 0 deletions Animoji/Model/SBSPuppetView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// SBSPuppetView.swift
// Animoji
//
// Created by Daniel Illescas Romero on 25/12/2017.
// Copyright © 2017 Daniel Illescas Romero. All rights reserved.
//

import UIKit

@objc protocol SBSPuppetViewDelegate: NSObjectProtocol {
func puppetViewDidFinishPlaying(puppetView: SBSPuppetView)
func puppetViewDidStartRecording(puppetView: SBSPuppetView)
func puppetViewDidStopRecording(puppetView: SBSPuppetView)
}

@objc class SBSPuppetView: AVTPuppetView {

var sbsDelegate: SBSPuppetViewDelegate?

override public func audioPlayerItemDidReachEnd(_ arg1: Any!) {
super.audioPlayerItemDidReachEnd(arg1)
if self.sbsDelegate?.responds(to: #selector(self.sbsDelegate?.puppetViewDidFinishPlaying(puppetView:))) == true {
self.sbsDelegate?.puppetViewDidFinishPlaying(puppetView: self)
}
}

override func startRecording() {
super.startRecording()

let recordingDuration = 60 // seconds

let duration = recordingDuration * 60

let timesBuffer = NSMutableData(capacity: duration * 8)
let blendShapeBuffer = NSMutableData(capacity: duration * 204)
let transformData = NSMutableData(capacity: duration * 64)

self.setValue(duration, forKey: "_recordingCapacity")
self.setValue(timesBuffer, forKey: "_rawTimesData")
self.setValue(blendShapeBuffer, forKey: "_rawBlendShapesData")
self.setValue(transformData, forKey: "_rawTransformsData")

if let ivarRawTimes = class_getInstanceVariable(AVTPuppetView.self, "_rawTimes") {
object_setIvar(self, ivarRawTimes, timesBuffer?.mutableBytes)
}

if let ivarBlendShapes = class_getInstanceVariable(AVTPuppetView.self, "_rawBlendShapes") {
object_setIvar(self, ivarBlendShapes, blendShapeBuffer?.mutableBytes)
}

if let ivarRawTransforms = class_getInstanceVariable(AVTPuppetView.self, "_rawTransforms") {
object_setIvar(self, ivarRawTransforms, transformData?.mutableBytes)
}

if self.sbsDelegate?.responds(to: #selector(self.sbsDelegate?.puppetViewDidStartRecording(puppetView:))) == true {
self.sbsDelegate?.puppetViewDidStartRecording(puppetView: self)
}
}

override func stopRecording() {
super.stopRecording()
if self.sbsDelegate?.responds(to: #selector(self.sbsDelegate?.puppetViewDidStopRecording(puppetView:))) == true {
self.sbsDelegate?.puppetViewDidStopRecording(puppetView: self)
}
}
}
Loading