Skip to content

Adds ability to animate contents of C4Image #588

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

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 27 additions & 4 deletions C4/UI/C4Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ public struct Pixel {
/// 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.
public class C4Image: C4View {

internal class ImageView : UIImageView {
var imageLayer: C4Layer {
get {
return self.layer as! C4Layer
}
}

override class func layerClass() -> AnyClass {
return C4Layer.self
}
}

/// C4Shape's contents are drawn on a C4ShapeLayer.
public var imageLayer: C4Layer {
get {
return self.imageView.imageLayer
}
}

internal var imageView: ImageView {
return self.view as! ImageView
}

//MARK: Initializers

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

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

if scale != 1.0 {
let scaledImage = UIImage(CGImage: uiimage.CGImage!, scale: CGFloat(scale), orientation: uiimage.imageOrientation)
self.view = UIImageView(image: scaledImage)
self.view = ImageView(image: scaledImage)
} else {
self.view = UIImageView(image: uiimage)
self.view = ImageView(image: uiimage)
}
_originalSize = C4Size(view.frame.size)
}
Expand Down Expand Up @@ -300,7 +323,7 @@ public class C4Image: C4View {
/// Returns the UIImageView of the object.
///
/// - returns: A UIImageView object.
internal var imageView : UIImageView {
internal var uiimageView : UIImageView {
get {
return self.view as! UIImageView
}
Expand Down
28 changes: 28 additions & 0 deletions C4/UI/C4Layer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// C4ImageLayer.swift
// C4iOS
//
// Created by travis on 2016-01-04.
// Copyright © 2016 C4. All rights reserved.
//

import QuartzCore

public class C4Layer: CALayer {
/// Configures basic options for a CABasicAnimation.
///
/// The options set in this method are favorable for the inner workings of C4's animation behaviours.
public override func actionForKey(key: String) -> CAAction? {
if C4ShapeLayer.disableActions == true {
return nil
}

if key == "contents" {
let animation = CABasicAnimation(keyPath: key)
animation.configureOptions()
animation.fromValue = self.contents
return animation;
}
return super.actionForKey(key)
}
}
4 changes: 4 additions & 0 deletions C4iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

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

/* Begin PBXFileReference section */
1F5486A31C3B9EF4005CEF19 /* C4Layer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = C4Layer.swift; sourceTree = "<group>"; };
1F8252CB1BB3C65E0090E98A /* C4Timer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = C4Timer.swift; sourceTree = "<group>"; };
1F8CB1D91A05781700A20783 /* C4RectTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = C4RectTests.swift; sourceTree = "<group>"; };
614F824319DB5ED3001DF1D4 /* C4.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = C4.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -339,6 +341,7 @@
A9D4F68A1B534F9F00F937AB /* C4Image+Filter.swift */,
A9D4F68B1B534F9F00F937AB /* C4Image+Generator.swift */,
A9D4F68C1B534F9F00F937AB /* C4Image.swift */,
1F5486A31C3B9EF4005CEF19 /* C4Layer.swift */,
A9D4F68D1B534F9F00F937AB /* C4Line.swift */,
A9D4F68E1B534F9F00F937AB /* C4Movie.swift */,
A9D4F68F1B534F9F00F937AB /* C4Polygon.swift */,
Expand Down Expand Up @@ -528,6 +531,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1F5486A41C3B9EF4005CEF19 /* C4Layer.swift in Sources */,
A9D4F6C81B534F9F00F937AB /* C4Line.swift in Sources */,
A9D4F6B01B534F9F00F937AB /* C4Math.swift in Sources */,
A9D4F6CD1B534F9F00F937AB /* C4RegularPolygon.swift in Sources */,
Expand Down