Commit 76e60ab6 by Orkhan Alikhanov

Added direction to DepthPreset

parent d82a9cd3
...@@ -30,14 +30,32 @@ ...@@ -30,14 +30,32 @@
import UIKit import UIKit
@objc(DepthPreset) public enum DepthPreset {
public enum DepthPreset: Int {
case none case none
case depth1 case depth1
case depth2 case depth2
case depth3 case depth3
case depth4 case depth4
case depth5 case depth5
indirect case above(DepthPreset)
indirect case below(DepthPreset)
indirect case left(DepthPreset)
indirect case right(DepthPreset)
public var root: DepthPreset {
switch self {
case .above(let v):
return v.root
case .below(let v):
return v.root
case .left(let v):
return v.root
case .right(let v):
return v.root
default:
return self
}
}
} }
public struct Depth { public struct Depth {
...@@ -110,5 +128,60 @@ public func DepthPresetToValue(preset: DepthPreset) -> Depth { ...@@ -110,5 +128,60 @@ public func DepthPresetToValue(preset: DepthPreset) -> Depth {
return Depth(offset: Offset(horizontal: 0, vertical: 4), opacity: 0.3, radius: 4) return Depth(offset: Offset(horizontal: 0, vertical: 4), opacity: 0.3, radius: 4)
case .depth5: case .depth5:
return Depth(offset: Offset(horizontal: 0, vertical: 8), opacity: 0.3, radius: 8) return Depth(offset: Offset(horizontal: 0, vertical: 8), opacity: 0.3, radius: 8)
case .above(let preset):
var v = DepthPresetToValue(preset: preset)
if preset.isRoot {
v.offset.vertical *= -1
} else {
let root = DepthPresetToValue(preset: preset.root)
v.offset.vertical -= root.offset.vertical
}
return v
case .below(let preset):
var v = DepthPresetToValue(preset: preset)
if preset.isRoot {
return v
} else {
let root = DepthPresetToValue(preset: preset.root)
v.offset.vertical += root.offset.vertical
}
return v
case .left(let preset):
var v = DepthPresetToValue(preset: preset)
if preset.isRoot {
v.offset.horizontal = -v.offset.vertical
v.offset.vertical = 0
} else {
let root = DepthPresetToValue(preset: preset.root)
v.offset.horizontal -= root.offset.vertical
}
return v
case .right(let preset):
var v = DepthPresetToValue(preset: preset)
if preset.isRoot {
v.offset.horizontal = v.offset.vertical
v.offset.vertical = 0
} else {
let root = DepthPresetToValue(preset: preset.root)
v.offset.horizontal += root.offset.vertical
}
return v
}
}
fileprivate extension DepthPreset {
var isRoot: Bool {
switch self {
case .above(_):
return false
case .below(_):
return false
case .left(_):
return false
case .right(_):
return false
default:
return true
}
} }
} }
...@@ -281,7 +281,7 @@ extension CALayer { ...@@ -281,7 +281,7 @@ extension CALayer {
return return
} }
if .none == depthPreset { if case .none = depthPreset.root {
shadowPath = nil shadowPath = nil
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
......
...@@ -87,7 +87,6 @@ extension UIView { ...@@ -87,7 +87,6 @@ extension UIView {
} }
/// A preset value for Depth. /// A preset value for Depth.
@objc
open var depthPreset: DepthPreset { open var depthPreset: DepthPreset {
get { get {
return layer.depthPreset return layer.depthPreset
......
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