-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationController.swift
More file actions
executable file
·75 lines (59 loc) · 2.56 KB
/
AnimationController.swift
File metadata and controls
executable file
·75 lines (59 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// AnimationController.swift
// ImagePickerSheet
//
// Created by Laurin Brandner on 25/05/15.
// Copyright (c) 2015 Laurin Brandner. All rights reserved.
//
import UIKit
class AnimationController: NSObject, UIViewControllerAnimatedTransitioning {
let imagePickerSheetController: ImagePickerSheetController
let presenting: Bool
// MARK: - Initialization
init(imagePickerSheetController: ImagePickerSheetController, presenting: Bool) {
self.imagePickerSheetController = imagePickerSheetController
self.presenting = presenting
}
// MARK: - UIViewControllerAnimatedTransitioning
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 0.3
}
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
if presenting {
animatePresentation(transitionContext)
}
else {
animateDismissal(transitionContext)
}
}
// MARK: - Animation
private func animatePresentation(context: UIViewControllerContextTransitioning) {
guard let containerView = context.containerView() else {
print ("ERROR: container view does not exist")
return
}
containerView.addSubview(imagePickerSheetController.view)
let tableViewOriginY = imagePickerSheetController.tableView.frame.origin.y
imagePickerSheetController.tableView.frame.origin.y = containerView.bounds.maxY
imagePickerSheetController.backgroundView.alpha = 0
UIView.animateWithDuration(transitionDuration(context), animations: {
self.imagePickerSheetController.tableView.frame.origin.y = tableViewOriginY
self.imagePickerSheetController.backgroundView.alpha = 1
}, completion: { _ in
context.completeTransition(true)
})
}
private func animateDismissal(context: UIViewControllerContextTransitioning) {
guard let containerView = context.containerView() else {
print ("ERROR: container view does not exist")
return
}
UIView.animateWithDuration(transitionDuration(context), animations: {
self.imagePickerSheetController.tableView.frame.origin.y = containerView.bounds.maxY
self.imagePickerSheetController.backgroundView.alpha = 0
}, completion: { _ in
self.imagePickerSheetController.view.removeFromSuperview()
context.completeTransition(true)
})
}
}