Skip to content

Commit 9a910de

Browse files
author
Danil Gontovnik
committed
Release 1.1
1 parent dc82241 commit 9a910de

File tree

12 files changed

+216
-100
lines changed

12 files changed

+216
-100
lines changed

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Periscope-VideoViewController
22
Video view controller with [Periscope](https://itunes.apple.com/us/app/periscope/id972909677?mt=8) fast rewind control.
33

4-
Tutorial on how to create this component can be found [here](https://medium.com/@gontovnik/building-periscope-fast-rewind-control-for-ios-5cb6801db0fd#.go2t3gdec).
4+
Tutorial on how to create this component can be found [here](https://medium.com/@gontovnik/building-periscope-fast-rewind-control-for-ios-5cb6801db0fd#.go2t3gdec).
55

66
![](https://raw.githubusercontent.com/gontovnik/Periscope-VideoViewController/master/VideoViewController.gif)
77

88
## Requirements
99
* Xcode 7 or higher
1010
* iOS 8.0 or higher (may work on previous versions, just did not test it)
1111
* ARC
12-
* Swift 2.0
12+
* Swift 3.0
1313

1414
## Demo
1515

@@ -18,9 +18,9 @@ Open and run the **VideoViewControllerExample** project in Xcode to see this com
1818
## Example usage
1919

2020
``` swift
21-
let videoURL = NSBundle.mainBundle().URLForResource("exampleVideo", withExtension: "mp4")!
21+
let videoURL = Bundle.main.url(forResource: "exampleVideo", withExtension: "mp4")!
2222
let videoViewController = VideoViewController(videoURL: videoURL)
23-
presentViewController(videoViewController, animated: true, completion: nil)
23+
present(videoViewController, animated: true, completion: nil)
2424
```
2525

2626
## Installation
@@ -48,9 +48,6 @@ Danil Gontovnik
4848
- http://gontovnik.com/
4949
5050

51-
I write here: https://medium.com/@gontovnik/
52-
And here: http://iostuts.io/author/danil-gontovnik/
53-
5451
## License
5552

5653
The MIT License (MIT)

VideoViewController.podspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
Pod::Spec.new do |spec|
22
spec.name = "VideoViewController"
3-
spec.version = "1.0"
3+
spec.version = "1.1"
44
spec.authors = { "Danil Gontovnik" => "[email protected]" }
55
spec.homepage = "https://github.com/gontovnik/Periscope-VideoViewController"
66
spec.summary = "Video view controller with Periscope fast rewind control"
7-
spec.source = { :git => "https://github.com/gontovnik/Periscope-VideoViewController.git", :tag => '1.0' }
7+
spec.source = { :git => "https://github.com/gontovnik/Periscope-VideoViewController.git", :tag => '1.1' }
88
spec.license = { :type => "MIT", :file => "LICENSE" }
9-
spec.platform = :ios, '8.0'
9+
spec.platform = :ios, '8.0'
1010
spec.source_files = "VideoViewController/*.swift"
1111

1212
spec.requires_arc = true
13-
13+
1414
spec.ios.deployment_target = '8.0'
1515
spec.ios.frameworks = ['UIKit', 'AVFoundation']
16-
end
16+
end

VideoViewController/TimelineView.swift

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,70 +22,70 @@
2222

2323
import UIKit
2424

25-
public class TimelineView: UIView {
25+
open class TimelineView: UIView {
2626

2727
// MARK: - Vars
2828

2929
/// The duration of the video in seconds.
30-
public var duration: NSTimeInterval = 0.0 {
30+
open var duration: TimeInterval = 0.0 {
3131
didSet { setNeedsDisplay() }
3232
}
3333

3434
/// Time in seconds when rewind began.
35-
public var initialTime: NSTimeInterval = 0.0 {
35+
open var initialTime: TimeInterval = 0.0 {
3636
didSet {
3737
currentTime = initialTime
3838
}
3939
}
4040

4141
/// Current timeline time in seconds.
42-
public var currentTime: NSTimeInterval = 0.0 {
42+
open var currentTime: TimeInterval = 0.0 {
4343
didSet {
4444
setNeedsDisplay()
4545
currentTimeDidChange?(currentTime)
4646
}
4747
}
4848

4949
/// Internal zoom variable.
50-
private var _zoom: CGFloat = 1.0 {
50+
fileprivate var _zoom: CGFloat = 1.0 {
5151
didSet { setNeedsDisplay() }
5252
}
5353

5454
/// The zoom of the timeline view. The higher zoom value, the more accurate rewind is. Default is 1.0.
55-
public var zoom: CGFloat {
55+
open var zoom: CGFloat {
5656
get { return _zoom }
5757
set { _zoom = max(min(newValue, maxZoom), minZoom) }
5858
}
5959

6060
/// Indicates minimum zoom value. Default is 1.0.
61-
public var minZoom: CGFloat = 1.0 {
61+
open var minZoom: CGFloat = 1.0 {
6262
didSet { zoom = _zoom }
6363
}
6464

6565
/// Indicates maximum zoom value. Default is 3.5.
66-
public var maxZoom: CGFloat = 3.5 {
66+
open var maxZoom: CGFloat = 3.5 {
6767
didSet { zoom = _zoom }
6868
}
6969

7070
/// The width of a line representing a specific time interval on a timeline. If zoom is not equal 1, then actual interval width equals to intervalWidth * zoom. Value will be used during rewind for calculations — for example, if zoom is 1, intervalWidth is 30 and intervalDuration is 15, then when user moves 10pixels left or right we will rewind by +5 or -5 seconds;
71-
public var intervalWidth: CGFloat = 24.0 {
71+
open var intervalWidth: CGFloat = 24.0 {
7272
didSet { setNeedsDisplay() }
7373
}
7474

7575
/// The duration of an interval in seconds. If video is 55 seconds and interval is 15 seconds — then we will have 3 full intervals and one not full interval. Value will be used during rewind for calculations.
76-
public var intervalDuration: CGFloat = 15.0 {
76+
open var intervalDuration: CGFloat = 15.0 {
7777
didSet { setNeedsDisplay() }
7878
}
7979

8080
/// Block which will be triggered everytime currentTime value changes.
81-
public var currentTimeDidChange: ((NSTimeInterval) -> ())?
81+
open var currentTimeDidChange: ((TimeInterval) -> ())?
8282

8383
// MARK: - Constructors
8484

8585
public init() {
8686
super.init(frame: .zero)
8787

88-
opaque = false
88+
isOpaque = false
8989
}
9090

9191
required public init?(coder aDecoder: NSCoder) {
@@ -97,7 +97,7 @@ public class TimelineView: UIView {
9797
/**
9898
Calculate current interval width. It takes two variables in count - intervalWidth and zoom.
9999
*/
100-
private func currentIntervalWidth() -> CGFloat {
100+
fileprivate func currentIntervalWidth() -> CGFloat {
101101
return intervalWidth * zoom
102102
}
103103

@@ -106,16 +106,16 @@ public class TimelineView: UIView {
106106

107107
- Parameter width: The distance.
108108
*/
109-
public func timeIntervalFromDistance(distance: CGFloat) -> NSTimeInterval {
110-
return NSTimeInterval(distance * intervalDuration / currentIntervalWidth())
109+
open func timeIntervalFromDistance(_ distance: CGFloat) -> TimeInterval {
110+
return TimeInterval(distance * intervalDuration / currentIntervalWidth())
111111
}
112112

113113
/**
114114
Calculates distance from given time interval.
115115

116116
- Parameter duration: The duration of an interval.
117117
*/
118-
public func distanceFromTimeInterval(timeInterval: NSTimeInterval) -> CGFloat {
118+
open func distanceFromTimeInterval(_ timeInterval: TimeInterval) -> CGFloat {
119119
return currentIntervalWidth() * CGFloat(timeInterval) / intervalDuration
120120
}
121121

@@ -124,15 +124,15 @@ public class TimelineView: UIView {
124124

125125
- Parameter distance: The distance how far it should rewind by.
126126
*/
127-
public func rewindByDistance(distance: CGFloat) {
127+
open func rewindByDistance(_ distance: CGFloat) {
128128
let newCurrentTime = currentTime + timeIntervalFromDistance(distance)
129129
currentTime = max(min(newCurrentTime, duration), 0.0)
130130
}
131131

132132
// MARK: - Draw
133133

134-
override public func drawRect(rect: CGRect) {
135-
super.drawRect(rect)
134+
override open func draw(_ rect: CGRect) {
135+
super.draw(rect)
136136

137137
let intervalWidth = currentIntervalWidth()
138138

@@ -144,30 +144,30 @@ public class TimelineView: UIView {
144144
let intervalsCount = CGFloat(duration) / intervalDuration
145145

146146
// Draw full line
147-
CGContextSetFillColorWithColor(context, UIColor(white: 0.45, alpha: 1.0).CGColor)
147+
context?.setFillColor(UIColor(white: 0.45, alpha: 1.0).cgColor)
148148

149-
let totalPath = UIBezierPath(roundedRect: CGRect(x: originX, y: 0.0, width: intervalWidth * intervalsCount, height: lineHeight), cornerRadius: lineHeight).CGPath
150-
CGContextAddPath(context, totalPath)
151-
CGContextFillPath(context)
149+
let totalPath = UIBezierPath(roundedRect: CGRect(x: originX, y: 0.0, width: intervalWidth * intervalsCount, height: lineHeight), cornerRadius: lineHeight).cgPath
150+
context?.addPath(totalPath)
151+
context?.fillPath()
152152

153153
// Draw elapsed line
154-
CGContextSetFillColorWithColor(context, UIColor.whiteColor().CGColor)
154+
context?.setFillColor(UIColor.white.cgColor)
155155

156-
let elapsedPath = UIBezierPath(roundedRect: CGRect(x: originX, y: 0.0, width: distanceFromTimeInterval(currentTime), height: lineHeight), cornerRadius: lineHeight).CGPath
157-
CGContextAddPath(context, elapsedPath)
158-
CGContextFillPath(context)
156+
let elapsedPath = UIBezierPath(roundedRect: CGRect(x: originX, y: 0.0, width: distanceFromTimeInterval(currentTime), height: lineHeight), cornerRadius: lineHeight).cgPath
157+
context?.addPath(elapsedPath)
158+
context?.fillPath()
159159

160160
// Draw current time dot
161-
CGContextFillEllipseInRect(context, CGRect(x: originX + distanceFromTimeInterval(initialTime), y: 7.0, width: 3.0, height: 3.0))
161+
context?.fillEllipse(in: CGRect(x: originX + distanceFromTimeInterval(initialTime), y: 7.0, width: 3.0, height: 3.0))
162162

163163
// Draw full line separators
164-
CGContextSetFillColorWithColor(context, UIColor(white: 0.0, alpha: 0.5).CGColor)
164+
context?.setFillColor(UIColor(white: 0.0, alpha: 0.5).cgColor)
165165

166166
var intervalIdx: CGFloat = 0.0
167167
repeat {
168168
intervalIdx += 1.0
169169
if intervalsCount - intervalIdx > 0.0 {
170-
CGContextFillRect(context, CGRect(x: originX + intervalWidth * intervalIdx, y: 0.0, width: 1.0, height: lineHeight))
170+
context?.fill(CGRect(x: originX + intervalWidth * intervalIdx, y: 0.0, width: 1.0, height: lineHeight))
171171
}
172172
} while intervalIdx < intervalsCount
173173
}

0 commit comments

Comments
 (0)