Skip to content

Adds copy methods to AudioPlayer, Gradient and Vector #637

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

Merged
merged 1 commit into from
Mar 2, 2016
Merged
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
8 changes: 8 additions & 0 deletions C4/Core/Vector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public struct Vector: Equatable, CustomStringConvertible {
z = 0
}

/// Initializes a Vector from another Vector
/// - parameter copy: a previously initialized Vector
public init(copy original: Vector) {
x = original.x
y = original.y
z = original.z
}

/// The polar representation magnitude of the vector.
/// ````
/// let v = Vector(x: 2.0, y: 1.0, z: 0.0)
Expand Down
7 changes: 7 additions & 0 deletions C4/UI/AudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import AVFoundation
public class AudioPlayer: NSObject, AVAudioPlayerDelegate {
internal var player: AVAudioPlayer!

var filename: String!

/// Initializes a new audio player from a given file name
/// ````
/// let ap = AudioPlayer("audioTrackFileName")
Expand All @@ -66,6 +68,11 @@ public class AudioPlayer: NSObject, AVAudioPlayerDelegate {

self.player = player
player.delegate = self
self.filename = name
}

public convenience init?(copy original: AudioPlayer) {
self.init(original.filename)
}

/// Plays a sound asynchronously.
Expand Down
30 changes: 25 additions & 5 deletions C4/UI/Gradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Gradient: View {
return gradientView.gradientLayer
}

var gradientView: GradientView {
internal var gradientView: GradientView {
return view as! GradientView // swiftlint:disable:this force_cast
}

Expand Down Expand Up @@ -101,18 +101,38 @@ public class Gradient: View {
}
}

/// The current rotation value of the view. Animatable.
/// - returns: A Double value representing the cumulative rotation of the view, measured in Radians.
public override var rotation: Double {
get {
if let number = gradientLayer.valueForKeyPath(Layer.rotationKey) as? NSNumber {
return number.doubleValue
}
return 0.0
}
set {
gradientLayer.setValue(newValue, forKeyPath: Layer.rotationKey)
}
}

/// Initializes a new Gradient.
///
/// - parameter frame: A Rect that defines the frame for the gradient's view.
/// - parameter colors: An array of Color objects that define the gradient's colors. Defaults to [C4Blue, C4Purple].
/// - parameter locations: An array of Double values that define the location of each gradient stop. Defaults to [0,1]
public convenience init(frame: Rect, colors: [Color] = [C4Blue, C4Purple], locations: [Double] = [0, 1]) {
assert(colors.count == locations.count, "colors and locations need to have the same number of elements")
public convenience override init(frame: Rect) {
self.init()
self.view = GradientView(frame: CGRect(frame))
self.colors = colors
self.locations = locations
self.colors = [C4Pink, C4Purple]
self.locations = [0, 1]
self.startPoint = Point()
self.endPoint = Point(1, 0)
}

public convenience init(copy original: Gradient) {
self.init(frame: original.frame)
self.colors = original.colors
self.locations = original.locations
copyViewStyle(original)
}
}
8 changes: 8 additions & 0 deletions C4/UI/GradientLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public class GradientLayer: CAGradientLayer {
/// This value can be set globally, after which changes to any shape's properties will be immediate.
public static var disableActions = true

private var _rotation = 0.0

/// The value of the receiver's current rotation state.
/// This value is cumulative, and can represent values beyong +/- π
public dynamic var rotation: Double {
return _rotation
}

/// This method searches for the given action object of the layer. Actions define dynamic behaviors for a layer. For example, the animatable properties of a layer typically have corresponding action objects to initiate the actual animations. When that property changes, the layer looks for the action object associated with the property name and executes it. You can also associate custom action objects with your layer to implement app-specific actions.
///
/// - parameter key: The identifier of the action.
Expand Down