Skip to content
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
110 changes: 50 additions & 60 deletions Camera/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,56 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<animations/>
</imageView>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceHorizontal="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="kMK-Kl-gUt">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="667" id="Urk-WK-fsP"/>
</constraints>
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="20" minimumInteritemSpacing="0.0" id="Ewi-8X-mRi" customClass="CollectionViewPagingFlowLayout" customModule="Camera" customModuleProvider="target">
<size key="itemSize" width="225" height="400"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" reuseIdentifier="CollectionViewCell" id="Oew-pC-wVK" customClass="CollectionViewCell" customModule="Camera" customModuleProvider="target">
<rect key="frame" x="0.0" y="133.5" width="225" height="400"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="225" height="400"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XKl-5Q-xqR">
<rect key="frame" x="0.0" y="0.0" width="225" height="400"/>
<animations/>
<color key="backgroundColor" red="0.50229090452194214" green="0.40129917860031128" blue="0.44941216707229614" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="2.9s" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oQG-p5-Z8l">
<rect key="frame" x="87" y="353" width="51" height="30"/>
<animations/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.5" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.99989169836044312" green="1" blue="0.99988096952438354" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<animations/>
<size key="customSize" width="225" height="400"/>
<connections>
<outlet property="clipView" destination="XKl-5Q-xqR" id="Xe5-AH-GQS"/>
<outlet property="sceneDuration" destination="oQG-p5-Z8l" id="raz-mX-OLL"/>
<segue destination="96O-5S-Syf" kind="presentation" identifier="EditClip" modalTransitionStyle="crossDissolve" id="bs0-ND-A2A">
<segue key="commit" inheritsFrom="parent" id="k9c-xf-l9r"/>
<segue key="preview" inheritsFrom="commit" id="BuD-71-Djj"/>
</segue>
</connections>
</collectionViewCell>
</cells>
</collectionView>
<button opaque="NO" alpha="0.69999998807907104" contentMode="center" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="F9c-jf-31W" userLabel="back to camera">
<rect key="frame" x="24" y="569" width="66" height="66"/>
<animations/>
Expand Down Expand Up @@ -324,66 +374,6 @@
<constraint firstAttribute="height" constant="66" id="HHx-4z-8Yd"/>
</constraints>
</view>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceHorizontal="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="kMK-Kl-gUt">
<rect key="frame" x="0.0" y="134" width="375" height="400"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="400" id="Urk-WK-fsP"/>
</constraints>
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="20" minimumInteritemSpacing="0.0" id="Ewi-8X-mRi" customClass="CollectionViewPagingFlowLayout" customModule="Camera" customModuleProvider="target">
<size key="itemSize" width="225" height="400"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" reuseIdentifier="CollectionViewCell" id="Oew-pC-wVK" customClass="CollectionViewCell" customModule="Camera" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="225" height="400"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="225" height="400"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XKl-5Q-xqR">
<rect key="frame" x="0.0" y="0.0" width="225" height="400"/>
<animations/>
<color key="backgroundColor" red="0.50229090452194214" green="0.40129917860031128" blue="0.44941216707229614" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="M2h-iI-QMS">
<rect key="frame" x="8" y="16" width="209" height="30"/>
<animations/>
<state key="normal" title="Delete">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="tapDelete:" destination="Oew-pC-wVK" eventType="touchUpInside" id="AB2-vg-dLY"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="2.9s" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oQG-p5-Z8l">
<rect key="frame" x="87" y="353" width="51" height="30"/>
<animations/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.5" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.99989169836044312" green="1" blue="0.99988096952438354" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<animations/>
<size key="customSize" width="225" height="400"/>
<connections>
<outlet property="clipView" destination="XKl-5Q-xqR" id="Xe5-AH-GQS"/>
<outlet property="sceneDuration" destination="oQG-p5-Z8l" id="raz-mX-OLL"/>
<segue destination="96O-5S-Syf" kind="presentation" identifier="EditClip" modalTransitionStyle="crossDissolve" id="bs0-ND-A2A">
<segue key="commit" inheritsFrom="parent" id="k9c-xf-l9r"/>
<segue key="preview" inheritsFrom="commit" id="BuD-71-Djj"/>
</segue>
</connections>
</collectionViewCell>
</cells>
</collectionView>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
Expand Down
7 changes: 0 additions & 7 deletions Camera/CollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,4 @@ class CollectionViewCell: UICollectionViewCell {
playerLayer!.videoGravity = AVLayerVideoGravityResize
clipView.layer.addSublayer(self.playerLayer!)
}

@IBAction func tapDelete(sender: UIButton) {
deleteSingleClip(clip)

// This is temporary instead of removing the row.
sender.enabled = false
}
}
14 changes: 14 additions & 0 deletions Camera/FileManagment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ func deleteSingleClip(clip: Clip) {
}
}

func deleteSingleClipAtIndex(index: Int) {
print("deleting clip at index \(index)")

let realm = try! Realm()
let clips = realm.objects(Clip).sorted("filename", ascending: true)

let clip = clips[index]
deleteClip(clip.filename)

try! realm.write {
realm.delete(clip)
}
}

func deleteAllClips() {
let clips = returnContentsOfClipsDirectory()

Expand Down
75 changes: 73 additions & 2 deletions Camera/ListViewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import AVKit
import AVFoundation
import RealmSwift

class ListViewViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate {
class ListViewViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate, UIGestureRecognizerDelegate {

@IBOutlet var mainView: UIView!
@IBOutlet weak var backgroundView: UIView!
@IBOutlet weak var clipCollection: UICollectionView!
@IBOutlet weak var bgImageView: UIImageView!

var screenEdgeRecognizer: UIScreenEdgePanGestureRecognizer!
var deleteGesture: UIPanGestureRecognizer!

var lightboxTransition: LightboxTransition!

Expand All @@ -39,6 +40,8 @@ class ListViewViewController: UIViewController, UICollectionViewDataSource, UICo
var loadingIndicator: UIActivityIndicatorView!
var blurView: UIVisualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Dark))

var clipOriginalY: CGFloat!

override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
Expand All @@ -54,6 +57,12 @@ class ListViewViewController: UIViewController, UICollectionViewDataSource, UICo
screenEdgeRecognizer.edges = .Left
view.addGestureRecognizer(screenEdgeRecognizer)

let deleteAction = Selector("deleteCell:")
deleteGesture = UIPanGestureRecognizer(target: self, action: deleteAction)

screenEdgeRecognizer.delegate = self
deleteGesture.delegate = self

lightboxTransition = LightboxTransition()

blurView.frame = self.view.bounds
Expand All @@ -68,6 +77,10 @@ class ListViewViewController: UIViewController, UICollectionViewDataSource, UICo
updateTableView()
}

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

Expand Down Expand Up @@ -165,12 +178,70 @@ class ListViewViewController: UIViewController, UICollectionViewDataSource, UICo
player!.muted = true
players.append(player)
playerLayers.append(playerLayer)

cell.addGestureRecognizer(deleteGesture)
// deleteGesture.enabled = false

NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerDidReachEndNotificationHandler:", name: "AVPlayerItemDidPlayToEndTimeNotification", object: player!.currentItem)

return cell
}

func deleteCell(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(view)
let velocity = sender.velocityInView(view)
let clipView = sender.view

if sender.state == .Began {
clipOriginalY = clipView!.frame.origin.y
}

if sender.state == .Changed {

clipView!.frame.origin.y = clipOriginalY + translation.y

print(translation.y)

if translation.y > 0 {
clipView!.frame.origin.y = clipOriginalY + (translation.y / 7)
}
}

if sender.state == .Ended {

print(velocity.y)

// if velocity.y < -350 || translation.y < -350 {
if translation.y < -350 {

UIView.animateWithDuration(0.6, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 10, options: [], animations: { () -> Void in

clipView!.frame.origin.y = 0 - self.view.frame.height

}, completion: { (Bool) -> Void in

print("deleting cell")
let cell = sender.view as! UICollectionViewCell
let index = self.clipCollection.indexPathForCell(cell)!.item
deleteSingleClipAtIndex(index)
self.clipCollection.reloadData()
})

print("deleting clip")

} else {

UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 10, options: [], animations: { () -> Void in

print("cancel deletion")
clipView?.frame.origin.y = self.clipOriginalY

}, completion: { (Bool) -> Void in
})
}
}
}

func scrollViewDidScroll(scrollView: UIScrollView) {
// let visibleRect: CGRect = CGRect(origin: self.clipCollection.contentOffset, size: self.clipCollection.bounds.size)
// let visiblePoint: CGPoint = CGPointMake(CGRectGetMidX(visibleRect), CGRectGetMidY(visibleRect))
Expand All @@ -186,7 +257,7 @@ class ListViewViewController: UIViewController, UICollectionViewDataSource, UICo
}

func scrollViewDidEndDecelerating(scrollView: UIScrollView) {

}

func playerDidReachEndNotificationHandler(notification: NSNotification) {
Expand Down