Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit 306717a

Browse files
wzxhasuricforever
authored andcommitted
feature: stream play video
1 parent eb1be3f commit 306717a

File tree

7 files changed

+296
-67
lines changed

7 files changed

+296
-67
lines changed

Demo.xcodeproj/project.pbxproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
isa = PBXProject;
120120
attributes = {
121121
LastSwiftUpdateCheck = 0720;
122-
LastUpgradeCheck = 0900;
122+
LastUpgradeCheck = 0940;
123123
ORGANIZATIONNAME = Teambition;
124124
TargetAttributes = {
125125
4A6BC7871C76F8C500DACDA5 = {
@@ -222,12 +222,14 @@
222222
CLANG_WARN_BOOL_CONVERSION = YES;
223223
CLANG_WARN_COMMA = YES;
224224
CLANG_WARN_CONSTANT_CONVERSION = YES;
225+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
225226
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
226227
CLANG_WARN_EMPTY_BODY = YES;
227228
CLANG_WARN_ENUM_CONVERSION = YES;
228229
CLANG_WARN_INFINITE_RECURSION = YES;
229230
CLANG_WARN_INT_CONVERSION = YES;
230231
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
232+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
231233
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
232234
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
233235
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -254,7 +256,7 @@
254256
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
255257
GCC_WARN_UNUSED_FUNCTION = YES;
256258
GCC_WARN_UNUSED_VARIABLE = YES;
257-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
259+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
258260
MTL_ENABLE_DEBUG_INFO = YES;
259261
ONLY_ACTIVE_ARCH = YES;
260262
SDKROOT = iphoneos;
@@ -275,12 +277,14 @@
275277
CLANG_WARN_BOOL_CONVERSION = YES;
276278
CLANG_WARN_COMMA = YES;
277279
CLANG_WARN_CONSTANT_CONVERSION = YES;
280+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
278281
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
279282
CLANG_WARN_EMPTY_BODY = YES;
280283
CLANG_WARN_ENUM_CONVERSION = YES;
281284
CLANG_WARN_INFINITE_RECURSION = YES;
282285
CLANG_WARN_INT_CONVERSION = YES;
283286
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
287+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
284288
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
285289
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
286290
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -301,7 +305,7 @@
301305
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
302306
GCC_WARN_UNUSED_FUNCTION = YES;
303307
GCC_WARN_UNUSED_VARIABLE = YES;
304-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
308+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
305309
MTL_ENABLE_DEBUG_INFO = NO;
306310
SDKROOT = iphoneos;
307311
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

Demo/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ViewController: UIViewController {
3737

3838
// mp4
3939

40-
let mp4 = URL(string: "https://tcs.teambition.net/storage/1013eff73697f68b5e981613debcdcf9673b?download=49DCA8D7-ADD7-487D-83E2-C414D6F9AE23.mp4&Signature=eyJhbGciOiJIUzI1NiJ9.eyJyZXNvdXJjZSI6Ii9zdG9yYWdlLzEwMTNlZmY3MzY5N2Y2OGI1ZTk4MTYxM2RlYmNkY2Y5NjczYiIsImV4cCI6MTUyMTY3NjgwMH0.lqC5zkN-URLa7QxvMpRu78O-4HMvicacIRTVClfnYKI")!
40+
let mp4 = URL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")!
4141
let mp4Item = FilePreviewItem(previewItemURL: mp4, previewItemTitle: "49DCA8D7-ADD7-487D-83E2-C414D6F9AE23.mp4", fileExtension: "mp4", fileKey: "1013eff73697f68b5e981613debcdcf9673b")
4242

4343
// .key

FilePreviewController.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
238238
GCC_WARN_UNUSED_FUNCTION = YES;
239239
GCC_WARN_UNUSED_VARIABLE = YES;
240-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
240+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
241241
MTL_ENABLE_DEBUG_INFO = YES;
242242
ONLY_ACTIVE_ARCH = YES;
243243
SDKROOT = iphoneos;
@@ -290,7 +290,7 @@
290290
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
291291
GCC_WARN_UNUSED_FUNCTION = YES;
292292
GCC_WARN_UNUSED_VARIABLE = YES;
293-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
293+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
294294
MTL_ENABLE_DEBUG_INFO = NO;
295295
SDKROOT = iphoneos;
296296
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

FilePreviewController.xcodeproj/xcshareddata/xcschemes/FilePreviewController.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0930"
3+
LastUpgradeVersion = "0940"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

FilePreviewController/FPAnimation.swift

Lines changed: 75 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ var AssociatedObjectHandle: UInt8 = 0
1414

1515
public extension UIViewController {
1616
public func presentFilePreviewController(viewControllerToPresent controller: UIViewController, fromView: UIView?) {
17-
if let fromView = fromView {
18-
let transitionDelegate = TransitionDelegate(fromView: fromView)
19-
controller.transitioningDelegate = transitionDelegate
20-
controller.fp_transitionDelegate = transitionDelegate
21-
}
17+
let transitionDelegate = TransitionDelegate(fromView: fromView)
18+
controller.transitioningDelegate = transitionDelegate
19+
controller.fp_transitionDelegate = transitionDelegate
2220
present(controller, animated: true, completion: nil)
2321
}
2422

@@ -42,7 +40,7 @@ public extension UIViewController {
4240
open class TransitionDelegate: NSObject, UIViewControllerTransitioningDelegate {
4341
open var fromView: UIView?
4442

45-
init(fromView: UIView) {
43+
init(fromView: UIView?) {
4644
super.init()
4745
self.fromView = fromView
4846
}
@@ -63,8 +61,8 @@ open class TransitionDelegate: NSObject, UIViewControllerTransitioningDelegate {
6361
}
6462

6563
open class PresentAnimation: NSObject, UIViewControllerAnimatedTransitioning {
66-
var fromView: UIView!
67-
public init(fromView: UIView) {
64+
var fromView: UIView?
65+
public init(fromView: UIView?) {
6866
super.init()
6967
self.fromView = fromView
7068
}
@@ -75,29 +73,43 @@ open class PresentAnimation: NSObject, UIViewControllerAnimatedTransitioning {
7573

7674
open func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
7775
let container = transitionContext.containerView
78-
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!
79-
80-
container.addSubview(toVC.view)
81-
let fromFrame = container.convert(fromView.frame, from: fromView.superview)
82-
let toFrame = transitionContext.finalFrame(for: toVC)
83-
84-
let scale = CGAffineTransform(scaleX: fromFrame.width/toFrame.width, y: fromFrame.height/toFrame.height)
85-
let translation = CGAffineTransform(translationX: fromFrame.midX - toFrame.midX, y: fromFrame.midY - toFrame.midY)
86-
toVC.view.transform = scale.concatenating(translation)
87-
toVC.view.alpha = 0
88-
89-
UIView.animate(withDuration: PresentDuration, delay: 0, options: UIViewAnimationOptions(), animations: {
90-
toVC.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
91-
toVC.view.alpha = 1
76+
guard let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to),
77+
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) else {
78+
return
79+
}
80+
if let fromView = fromView {
81+
container.addSubview(toViewController.view)
82+
let fromFrame = container.convert(fromView.frame, from: fromView.superview)
83+
let toFrame = transitionContext.finalFrame(for: toViewController)
84+
85+
let scale = CGAffineTransform(scaleX: fromFrame.width/toFrame.width, y: fromFrame.height/toFrame.height)
86+
let translation = CGAffineTransform(translationX: fromFrame.midX - toFrame.midX, y: fromFrame.midY - toFrame.midY)
87+
toViewController.view.transform = scale.concatenating(translation)
88+
toViewController.view.alpha = 0
89+
90+
UIView.animate(withDuration: PresentDuration, delay: 0, options: UIViewAnimationOptions(), animations: {
91+
toViewController.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
92+
toViewController.view.alpha = 1
93+
}) { (_) in
94+
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
95+
}
96+
} else {
97+
var frame = fromViewController.view.frame
98+
frame.origin.y = frame.size.height
99+
toViewController.view.frame = frame
100+
container.addSubview(toViewController.view)
101+
UIView.animate(withDuration: PresentDuration, delay: 0, options: .curveEaseIn, animations: {
102+
toViewController.view.frame = fromViewController.view.frame
92103
}) { (_) in
93104
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
105+
}
94106
}
95107
}
96108
}
97109

98110
open class DismissAnimation: NSObject, UIViewControllerAnimatedTransitioning {
99-
var toView: UIView!
100-
public init(toView: UIView) {
111+
var toView: UIView?
112+
public init(toView: UIView?) {
101113
super.init()
102114
self.toView = toView
103115
}
@@ -108,23 +120,47 @@ open class DismissAnimation: NSObject, UIViewControllerAnimatedTransitioning {
108120

109121
open func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
110122
let container = transitionContext.containerView
111-
let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
112-
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!
113-
114-
toVC.view.frame = transitionContext.finalFrame(for: toVC)
115-
container.addSubview(toVC.view)
116-
container.addSubview(fromVC.view)
117-
let toFrame = container.convert(toView.frame, from: toView.superview)
118-
let fromFrame = transitionContext.finalFrame(for: fromVC)
119-
120-
let scale = CGAffineTransform(scaleX: toFrame.width/fromFrame.width, y: toFrame.height/fromFrame.height)
121-
let translation = CGAffineTransform(translationX: toFrame.midX - fromFrame.midX, y: toFrame.midY - fromFrame.midY)
122-
UIView.animate(withDuration: DismissDuration, delay: 0, options: .curveEaseOut, animations: {
123-
fromVC.view.alpha = 0
124-
fromVC.view.transform = scale.concatenating(translation)
123+
guard let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to),
124+
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) else {
125+
return
126+
}
127+
128+
func willDismiss() {
129+
if let navigationViewController = fromViewController as? UINavigationController,
130+
let filePreviewController = navigationViewController.viewControllers.last as? FilePreviewController {
131+
filePreviewController.willDismiss()
132+
} else {
133+
(fromViewController as? FilePreviewController)?.willDismiss()
134+
}
135+
}
136+
137+
if let toView = toView {
138+
toViewController.view.frame = transitionContext.finalFrame(for: toViewController)
139+
container.addSubview(toViewController.view)
140+
container.addSubview(fromViewController.view)
141+
let toFrame = container.convert(toView.frame, from: toView.superview)
142+
let fromFrame = transitionContext.finalFrame(for: fromViewController)
143+
144+
let scale = CGAffineTransform(scaleX: toFrame.width/fromFrame.width, y: toFrame.height/fromFrame.height)
145+
let translation = CGAffineTransform(translationX: toFrame.midX - fromFrame.midX, y: toFrame.midY - fromFrame.midY)
146+
UIView.animate(withDuration: DismissDuration, delay: 0, options: .curveEaseOut, animations: {
147+
fromViewController.view.alpha = 0
148+
fromViewController.view.transform = scale.concatenating(translation)
149+
}) { (_) in
150+
willDismiss()
151+
fromViewController.view.removeFromSuperview()
152+
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
153+
}
154+
} else {
155+
var frame = fromViewController.view.frame
156+
frame.origin.y = frame.size.height
157+
UIView.animate(withDuration: DismissDuration, delay: 0, options: .curveEaseIn, animations: {
158+
fromViewController.view.frame = frame
125159
}) { (_) in
126-
fromVC.view.removeFromSuperview()
160+
willDismiss()
161+
fromViewController.view.removeFromSuperview()
127162
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
163+
}
128164
}
129165
}
130166
}

FilePreviewController/FilePreviewController.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010
import QuickLook
1111
import Alamofire
1212
import UIKit
13+
1314
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
1415
switch (lhs, rhs) {
1516
case let (l?, r?):
@@ -140,7 +141,7 @@ open class FilePreviewController: QLPreviewController {
140141
progressView.tintColor = UIColor.blue
141142
return progressView
142143
}()
143-
fileprivate var shouldDisplayToolbar: Bool {
144+
var shouldDisplayToolbar: Bool {
144145
get {
145146
return items?.count > 0
146147
}
@@ -279,11 +280,7 @@ open class FilePreviewController: QLPreviewController {
279280
customNavigationBar = customHeaderView
280281
}
281282
}
282-
283-
open override func viewDidAppear(_ animated: Bool) {
284-
super.viewDidAppear(animated)
285-
}
286-
283+
287284
deinit {
288285
if let navigationBar = navigationBar {
289286
navigationBar.removeObserver(self, forKeyPath: "center")
@@ -328,13 +325,13 @@ open class FilePreviewController: QLPreviewController {
328325
self.view.layoutIfNeeded()
329326
self.navigationBar?.superview?.layoutIfNeeded()
330327
self.originalToolbar?.isHidden = true
331-
self.navigationBar?.superview?.bringSubview(toFront: self.customNavigationBar!)
332328
}, completion: { (_) in
333329
self.originalToolbar?.isHidden = true
334330
DispatchQueue.main.async {
335331
self.navigationBar?.superview?.bringSubview(toFront: self.customNavigationBar!)
336332
}
337333
})
334+
338335
}
339336
setNeedsStatusBarAppearanceUpdate()
340337
}
@@ -350,6 +347,8 @@ open class FilePreviewController: QLPreviewController {
350347
presentingViewController?.dismissFilePreviewController()
351348
}
352349

350+
func willDismiss() {}
351+
353352
func getNavigationBar(fromView view: UIView) -> UINavigationBar? {
354353
for v in view.subviews {
355354
if v is UINavigationBar {

0 commit comments

Comments
 (0)