Skip to content

Commit 578354e

Browse files
committed
Adds ability to animate contents of C4Image
1 parent 83d0109 commit 578354e

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

Diff for: C4/UI/C4Image.swift

+27-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ public struct Pixel {
5757
/// A C4Image provides a view-based container for displaying a single image. You can create images from files, from other image objects, or from raw image data you receive.
5858
public class C4Image: C4View {
5959

60+
internal class ImageView : UIImageView {
61+
var imageLayer: C4Layer {
62+
get {
63+
return self.layer as! C4Layer
64+
}
65+
}
66+
67+
override class func layerClass() -> AnyClass {
68+
return C4Layer.self
69+
}
70+
}
71+
72+
/// C4Shape's contents are drawn on a C4ShapeLayer.
73+
public var imageLayer: C4Layer {
74+
get {
75+
return self.imageView.imageLayer
76+
}
77+
}
78+
79+
internal var imageView: ImageView {
80+
return self.view as! ImageView
81+
}
82+
6083
//MARK: Initializers
6184

6285
/// Initializes a new C4Image using the specified filename from the bundle (i.e. your project), it will also grab images
@@ -102,7 +125,7 @@ public class C4Image: C4View {
102125
convenience public init(image: C4Image) {
103126
self.init()
104127
let uiimage = image.uiimage
105-
self.view = UIImageView(image: uiimage)
128+
self.view = ImageView(image: uiimage)
106129
}
107130

108131
/// Initializes a new C4Image using a UIImage.
@@ -135,9 +158,9 @@ public class C4Image: C4View {
135158

136159
if scale != 1.0 {
137160
let scaledImage = UIImage(CGImage: uiimage.CGImage!, scale: CGFloat(scale), orientation: uiimage.imageOrientation)
138-
self.view = UIImageView(image: scaledImage)
161+
self.view = ImageView(image: scaledImage)
139162
} else {
140-
self.view = UIImageView(image: uiimage)
163+
self.view = ImageView(image: uiimage)
141164
}
142165
_originalSize = C4Size(view.frame.size)
143166
}
@@ -300,7 +323,7 @@ public class C4Image: C4View {
300323
/// Returns the UIImageView of the object.
301324
///
302325
/// - returns: A UIImageView object.
303-
internal var imageView : UIImageView {
326+
internal var uiimageView : UIImageView {
304327
get {
305328
return self.view as! UIImageView
306329
}

Diff for: C4/UI/C4Layer.swift

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// C4ImageLayer.swift
3+
// C4iOS
4+
//
5+
// Created by travis on 2016-01-04.
6+
// Copyright © 2016 C4. All rights reserved.
7+
//
8+
9+
import QuartzCore
10+
11+
public class C4Layer: CALayer {
12+
/// Configures basic options for a CABasicAnimation.
13+
///
14+
/// The options set in this method are favorable for the inner workings of C4's animation behaviours.
15+
public override func actionForKey(key: String) -> CAAction? {
16+
if C4ShapeLayer.disableActions == true {
17+
return nil
18+
}
19+
20+
if key == "contents" {
21+
let animation = CABasicAnimation(keyPath: key)
22+
animation.configureOptions()
23+
animation.fromValue = self.contents
24+
return animation;
25+
}
26+
return super.actionForKey(key)
27+
}
28+
}

Diff for: C4iOS.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
1F5486A41C3B9EF4005CEF19 /* C4Layer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F5486A31C3B9EF4005CEF19 /* C4Layer.swift */; };
1011
1F8252CC1BB3C65E0090E98A /* C4Timer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F8252CB1BB3C65E0090E98A /* C4Timer.swift */; };
1112
61BBAF631BC372BD00A03FD0 /* C4StoredAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BBAF621BC372BD00A03FD0 /* C4StoredAnimation.swift */; };
1213
61BBAF651BC38C1200A03FD0 /* C4View+KeyValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BBAF641BC38C1200A03FD0 /* C4View+KeyValues.swift */; };
@@ -122,6 +123,7 @@
122123
/* End PBXCopyFilesBuildPhase section */
123124

124125
/* Begin PBXFileReference section */
126+
1F5486A31C3B9EF4005CEF19 /* C4Layer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = C4Layer.swift; sourceTree = "<group>"; };
125127
1F8252CB1BB3C65E0090E98A /* C4Timer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = C4Timer.swift; sourceTree = "<group>"; };
126128
1F8CB1D91A05781700A20783 /* C4RectTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = C4RectTests.swift; sourceTree = "<group>"; };
127129
614F824319DB5ED3001DF1D4 /* C4.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = C4.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -339,6 +341,7 @@
339341
A9D4F68A1B534F9F00F937AB /* C4Image+Filter.swift */,
340342
A9D4F68B1B534F9F00F937AB /* C4Image+Generator.swift */,
341343
A9D4F68C1B534F9F00F937AB /* C4Image.swift */,
344+
1F5486A31C3B9EF4005CEF19 /* C4Layer.swift */,
342345
A9D4F68D1B534F9F00F937AB /* C4Line.swift */,
343346
A9D4F68E1B534F9F00F937AB /* C4Movie.swift */,
344347
A9D4F68F1B534F9F00F937AB /* C4Polygon.swift */,
@@ -528,6 +531,7 @@
528531
isa = PBXSourcesBuildPhase;
529532
buildActionMask = 2147483647;
530533
files = (
534+
1F5486A41C3B9EF4005CEF19 /* C4Layer.swift in Sources */,
531535
A9D4F6C81B534F9F00F937AB /* C4Line.swift in Sources */,
532536
A9D4F6B01B534F9F00F937AB /* C4Math.swift in Sources */,
533537
A9D4F6CD1B534F9F00F937AB /* C4RegularPolygon.swift in Sources */,

0 commit comments

Comments
 (0)