Commit c9b17207 by Daniel Dahan

added extensions

parent 96c1064f
...@@ -7,15 +7,21 @@ ...@@ -7,15 +7,21 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
961409AA1E43CF1B00E7BA99 /* Motion+Obj-C.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961409A91E43CF1B00E7BA99 /* Motion+Obj-C.swift */; };
961409AE1E43CFFD00E7BA99 /* Motion+UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961409AD1E43CFFD00E7BA99 /* Motion+UIView.swift */; };
961409B61E43D17200E7BA99 /* Motion+Obj-C.swift in Headers */ = {isa = PBXBuildFile; fileRef = 961409A91E43CF1B00E7BA99 /* Motion+Obj-C.swift */; settings = {ATTRIBUTES = (Public, ); }; };
961409B71E43D17200E7BA99 /* Motion+UIView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 961409AD1E43CFFD00E7BA99 /* Motion+UIView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
961409B81E43D21300E7BA99 /* Motion.h in Headers */ = {isa = PBXBuildFile; fileRef = 96C98DED1E438A5700B22906 /* Motion.h */; settings = {ATTRIBUTES = (Public, ); }; };
96C98DE41E4382B100B22906 /* Motion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C98DE31E4382B100B22906 /* Motion.swift */; }; 96C98DE41E4382B100B22906 /* Motion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C98DE31E4382B100B22906 /* Motion.swift */; };
96C98DE61E43848500B22906 /* MotionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C98DE51E43848500B22906 /* MotionAnimation.swift */; }; 96C98DE61E43848500B22906 /* MotionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C98DE51E43848500B22906 /* MotionAnimation.swift */; };
96C98DE81E43849B00B22906 /* MotionTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C98DE71E43849B00B22906 /* MotionTransition.swift */; }; 96C98DE81E43849B00B22906 /* MotionTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C98DE71E43849B00B22906 /* MotionTransition.swift */; };
96C98DEA1E4389BE00B22906 /* Motion.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96C98DE31E4382B100B22906 /* Motion.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96C98DEB1E4389BE00B22906 /* MotionAnimation.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96C98DE51E43848500B22906 /* MotionAnimation.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96C98DEB1E4389BE00B22906 /* MotionAnimation.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96C98DE51E43848500B22906 /* MotionAnimation.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96C98DEC1E4389BE00B22906 /* MotionTransition.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96C98DE71E43849B00B22906 /* MotionTransition.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96C98DEC1E4389BE00B22906 /* MotionTransition.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96C98DE71E43849B00B22906 /* MotionTransition.swift */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
961409A91E43CF1B00E7BA99 /* Motion+Obj-C.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Motion+Obj-C.swift"; sourceTree = "<group>"; };
961409AD1E43CFFD00E7BA99 /* Motion+UIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Motion+UIView.swift"; sourceTree = "<group>"; };
96C98DD11E424AB000B22906 /* Motion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Motion.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 96C98DD11E424AB000B22906 /* Motion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Motion.framework; sourceTree = BUILT_PRODUCTS_DIR; };
96C98DDD1E424B9000B22906 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 96C98DDD1E424B9000B22906 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96C98DE21E43809D00B22906 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; }; 96C98DE21E43809D00B22906 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
...@@ -61,6 +67,8 @@ ...@@ -61,6 +67,8 @@
96C98DE31E4382B100B22906 /* Motion.swift */, 96C98DE31E4382B100B22906 /* Motion.swift */,
96C98DE51E43848500B22906 /* MotionAnimation.swift */, 96C98DE51E43848500B22906 /* MotionAnimation.swift */,
96C98DE71E43849B00B22906 /* MotionTransition.swift */, 96C98DE71E43849B00B22906 /* MotionTransition.swift */,
961409A91E43CF1B00E7BA99 /* Motion+Obj-C.swift */,
961409AD1E43CFFD00E7BA99 /* Motion+UIView.swift */,
); );
path = Sources; path = Sources;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -72,7 +80,9 @@ ...@@ -72,7 +80,9 @@
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96C98DEA1E4389BE00B22906 /* Motion.swift in Headers */, 961409B81E43D21300E7BA99 /* Motion.h in Headers */,
961409B61E43D17200E7BA99 /* Motion+Obj-C.swift in Headers */,
961409B71E43D17200E7BA99 /* Motion+UIView.swift in Headers */,
96C98DEB1E4389BE00B22906 /* MotionAnimation.swift in Headers */, 96C98DEB1E4389BE00B22906 /* MotionAnimation.swift in Headers */,
96C98DEC1E4389BE00B22906 /* MotionTransition.swift in Headers */, 96C98DEC1E4389BE00B22906 /* MotionTransition.swift in Headers */,
); );
...@@ -147,7 +157,9 @@ ...@@ -147,7 +157,9 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
961409AE1E43CFFD00E7BA99 /* Motion+UIView.swift in Sources */,
96C98DE61E43848500B22906 /* MotionAnimation.swift in Sources */, 96C98DE61E43848500B22906 /* MotionAnimation.swift in Sources */,
961409AA1E43CF1B00E7BA99 /* Motion+Obj-C.swift in Sources */,
96C98DE41E4382B100B22906 /* Motion.swift in Sources */, 96C98DE41E4382B100B22906 /* Motion.swift in Sources */,
96C98DE81E43849B00B22906 /* MotionTransition.swift in Sources */, 96C98DE81E43849B00B22906 /* MotionTransition.swift in Sources */,
); );
...@@ -271,7 +283,7 @@ ...@@ -271,7 +283,7 @@
PRODUCT_MODULE_NAME = Motion; PRODUCT_MODULE_NAME = Motion;
PRODUCT_NAME = Motion; PRODUCT_NAME = Motion;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME).h"; SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0; SWIFT_VERSION = 3.0;
}; };
...@@ -293,7 +305,7 @@ ...@@ -293,7 +305,7 @@
PRODUCT_MODULE_NAME = Motion; PRODUCT_MODULE_NAME = Motion;
PRODUCT_NAME = Motion; PRODUCT_NAME = Motion;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME).h"; SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
SWIFT_VERSION = 3.0; SWIFT_VERSION = 3.0;
}; };
name = Release; name = Release;
......
/*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
Gets the Obj-C reference for the instance object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- Parameter initializer: Object initializer.
- Returns: The associated reference for the initializer object.
*/
internal func AssociatedObject<T: Any>(base: Any, key: UnsafePointer<UInt8>, initializer: () -> T) -> T {
if let v = objc_getAssociatedObject(base, key) as? T {
return v
}
let v = initializer()
objc_setAssociatedObject(base, key, v, .OBJC_ASSOCIATION_RETAIN)
return v
}
/**
Sets the Obj-C reference for the instance object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- Parameter value: The object instance to set for the associated object.
- Returns: The associated reference for the initializer object.
*/
internal func AssociateObject<T: Any>(base: Any, key: UnsafePointer<UInt8>, value: T) {
objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN)
}
/*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
/// Grid extension for UIView.
extension UIView {
/// A property that accesses the backing layer's masksToBounds.
@IBInspectable
open var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/// A property that accesses the backing layer's opacity.
@IBInspectable
open var opacity: Float {
get {
return layer.opacity
}
set(value) {
layer.opacity = value
}
}
/// A property that accesses the backing layer's anchorPoint.
@IBInspectable
open var anchorPoint: CGPoint {
get {
return layer.anchorPoint
}
set(value) {
layer.anchorPoint = value
}
}
/// A property that accesses the backing layer's shadow
@IBInspectable
open var shadowColor: UIColor? {
get {
guard let v = layer.shadowColor else {
return nil
}
return UIColor(cgColor: v)
}
set(value) {
layer.shadowColor = value?.cgColor
}
}
/// A property that accesses the backing layer's shadowOffset.
@IBInspectable
open var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/// A property that accesses the backing layer's shadowOpacity.
@IBInspectable
open var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/// A property that accesses the backing layer's shadowRadius.
@IBInspectable
open var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/// A property that accesses the backing layer's shadowPath.
@IBInspectable
open var shadowPath: CGPath? {
get {
return layer.shadowPath
}
set(value) {
layer.shadowPath = value
}
}
/// A property that accesses the layer.cornerRadius.
@IBInspectable
open var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set(value) {
layer.cornerRadius = value
}
}
/// A property that accesses the layer.borderWith.
@IBInspectable
open var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set(value) {
layer.borderWidth = value
}
}
/// A property that accesses the layer.borderColor property.
@IBInspectable
open var borderColor: UIColor? {
get {
guard let v = layer.borderColor else {
return nil
}
return UIColor(cgColor: v)
}
set(value) {
layer.borderColor = value?.cgColor
}
}
/// A property that accesses the layer.position property.
@IBInspectable
open var position: CGPoint {
get {
return layer.position
}
set(value) {
layer.position = value
}
}
/// A property that accesses the layer.zPosition property.
@IBInspectable
open var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
}
}
}
...@@ -98,7 +98,7 @@ public struct Motion { ...@@ -98,7 +98,7 @@ public struct Motion {
public static func delay(_ time: TimeInterval, execute block: @escaping () -> Void) -> MotionDelayCancelBlock? { public static func delay(_ time: TimeInterval, execute block: @escaping () -> Void) -> MotionDelayCancelBlock? {
func asyncAfter(completion: @escaping () -> Void) { func asyncAfter(completion: @escaping () -> Void) {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + time, execute: completion) DispatchQueue.main.asyncAfter(deadline: .now() + time, execute: completion)
} }
var cancelable: MotionDelayCancelBlock? var cancelable: MotionDelayCancelBlock?
......
...@@ -135,8 +135,6 @@ extension UIView { ...@@ -135,8 +135,6 @@ extension UIView {
open func motionTransitionSnapshot(afterUpdates: Bool) -> UIView { open func motionTransitionSnapshot(afterUpdates: Bool) -> UIView {
isHidden = false isHidden = false
(self as? Pulseable)?.pulse.pulseLayer?.isHidden = true
let oldCornerRadius = cornerRadius let oldCornerRadius = cornerRadius
cornerRadius = 0 cornerRadius = 0
...@@ -175,7 +173,6 @@ extension UIView { ...@@ -175,7 +173,6 @@ extension UIView {
v.backgroundColor = backgroundColor v.backgroundColor = backgroundColor
isHidden = true isHidden = true
(self as? Pulseable)?.pulse.pulseLayer?.isHidden = false
return v return v
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment