Commit 9a90a7d5 by Daniel Dahan

cleanup and removal of duplicate code

parent e15b9fff
......@@ -14,7 +14,6 @@
9660161D1CB2ED6C00AAB661 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 966016131CB2ED6C00AAB661 /* Material.framework */; };
9660162A1CB2F04E00AAB661 /* Material.h in Headers */ = {isa = PBXBuildFile; fileRef = 96D88C091C1328D800B91418 /* Material.h */; settings = {ATTRIBUTES = (Public, ); }; };
966ECF2A1CF4C20100BB0BDF /* MaterialCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966ECF291CF4C20100BB0BDF /* MaterialCollectionReusableView.swift */; };
9679CEAB1CC69E080021685B /* Material+UIImage+TintColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9679CEAA1CC69E080021685B /* Material+UIImage+TintColor.swift */; };
967A48191D0F425A00B8CEB7 /* StatusBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967A48181D0F425A00B8CEB7 /* StatusBarController.swift */; };
96815B381CA07BA20006CBE2 /* MaterialViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967887881C9777CB0037F6C9 /* MaterialViewTests.swift */; };
968C99451D37730B000074FF /* Direction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 968C99441D37730B000074FF /* Direction.swift */; };
......@@ -34,12 +33,6 @@
96BCB7AC1CB40DC500C806FE /* Material+Obj-C.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7631CB40DC500C806FE /* Material+Obj-C.swift */; };
96BCB7AD1CB40DC500C806FE /* Material+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7641CB40DC500C806FE /* Material+String.swift */; };
96BCB7AE1CB40DC500C806FE /* Material+UIFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7651CB40DC500C806FE /* Material+UIFont.swift */; };
96BCB7AF1CB40DC500C806FE /* Material+UIImage+Blank.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7661CB40DC500C806FE /* Material+UIImage+Blank.swift */; };
96BCB7B01CB40DC500C806FE /* Material+UIImage+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7671CB40DC500C806FE /* Material+UIImage+Color.swift */; };
96BCB7B11CB40DC500C806FE /* Material+UIImage+Crop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7681CB40DC500C806FE /* Material+UIImage+Crop.swift */; };
96BCB7B21CB40DC500C806FE /* Material+UIImage+Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7691CB40DC500C806FE /* Material+UIImage+Network.swift */; };
96BCB7B31CB40DC500C806FE /* Material+UIImage+Resize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB76A1CB40DC500C806FE /* Material+UIImage+Resize.swift */; };
96BCB7B41CB40DC500C806FE /* Material+UIImage+Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB76B1CB40DC500C806FE /* Material+UIImage+Size.swift */; };
96BCB7B51CB40DC500C806FE /* Material+UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB76C1CB40DC500C806FE /* Material+UIImage.swift */; };
96BCB7B61CB40DC500C806FE /* Animation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB76D1CB40DC500C806FE /* Animation.swift */; };
96BCB7B71CB40DC500C806FE /* BasicAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB76E1CB40DC500C806FE /* BasicAnimation.swift */; };
......@@ -129,12 +122,6 @@
96BCB8271CB4115200C806FE /* Material+Obj-C.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7631CB40DC500C806FE /* Material+Obj-C.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB8281CB4115200C806FE /* Material+String.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7641CB40DC500C806FE /* Material+String.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB8291CB4115200C806FE /* Material+UIFont.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7651CB40DC500C806FE /* Material+UIFont.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB82A1CB4115200C806FE /* Material+UIImage+Blank.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7661CB40DC500C806FE /* Material+UIImage+Blank.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB82B1CB4115200C806FE /* Material+UIImage+Color.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7671CB40DC500C806FE /* Material+UIImage+Color.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB82C1CB4115200C806FE /* Material+UIImage+Crop.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7681CB40DC500C806FE /* Material+UIImage+Crop.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB82D1CB4115200C806FE /* Material+UIImage+Network.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7691CB40DC500C806FE /* Material+UIImage+Network.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB82E1CB4115200C806FE /* Material+UIImage+Resize.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB76A1CB40DC500C806FE /* Material+UIImage+Resize.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB82F1CB4115200C806FE /* Material+UIImage+Size.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB76B1CB40DC500C806FE /* Material+UIImage+Size.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB8301CB4115200C806FE /* Material+UIImage.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB76C1CB40DC500C806FE /* Material+UIImage.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB8311CB4115200C806FE /* Font.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB77B1CB40DC500C806FE /* Font.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB8321CB4115200C806FE /* RobotoFont.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7941CB40DC500C806FE /* RobotoFont.swift */; settings = {ATTRIBUTES = (Public, ); }; };
......@@ -209,7 +196,6 @@
9660161C1CB2ED6C00AAB661 /* Material OSX Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Material OSX Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
966ECF291CF4C20100BB0BDF /* MaterialCollectionReusableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionReusableView.swift; sourceTree = "<group>"; };
967887881C9777CB0037F6C9 /* MaterialViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialViewTests.swift; sourceTree = "<group>"; };
9679CEAA1CC69E080021685B /* Material+UIImage+TintColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+TintColor.swift"; sourceTree = "<group>"; };
967A48181D0F425A00B8CEB7 /* StatusBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = "<group>"; };
968C99441D37730B000074FF /* Direction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Direction.swift; sourceTree = "<group>"; };
968C99461D377849000074FF /* Offset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Offset.swift; sourceTree = "<group>"; };
......@@ -228,12 +214,6 @@
96BCB7631CB40DC500C806FE /* Material+Obj-C.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+Obj-C.swift"; sourceTree = "<group>"; };
96BCB7641CB40DC500C806FE /* Material+String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+String.swift"; sourceTree = "<group>"; };
96BCB7651CB40DC500C806FE /* Material+UIFont.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIFont.swift"; sourceTree = "<group>"; };
96BCB7661CB40DC500C806FE /* Material+UIImage+Blank.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+Blank.swift"; sourceTree = "<group>"; };
96BCB7671CB40DC500C806FE /* Material+UIImage+Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+Color.swift"; sourceTree = "<group>"; };
96BCB7681CB40DC500C806FE /* Material+UIImage+Crop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+Crop.swift"; sourceTree = "<group>"; };
96BCB7691CB40DC500C806FE /* Material+UIImage+Network.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+Network.swift"; sourceTree = "<group>"; };
96BCB76A1CB40DC500C806FE /* Material+UIImage+Resize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+Resize.swift"; sourceTree = "<group>"; };
96BCB76B1CB40DC500C806FE /* Material+UIImage+Size.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+Size.swift"; sourceTree = "<group>"; };
96BCB76C1CB40DC500C806FE /* Material+UIImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage.swift"; sourceTree = "<group>"; };
96BCB76D1CB40DC500C806FE /* Animation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Animation.swift; sourceTree = "<group>"; };
96BCB76E1CB40DC500C806FE /* BasicAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicAnimation.swift; sourceTree = "<group>"; };
......@@ -586,15 +566,8 @@
96BCB7631CB40DC500C806FE /* Material+Obj-C.swift */,
96BCB7641CB40DC500C806FE /* Material+String.swift */,
96BCB7651CB40DC500C806FE /* Material+UIFont.swift */,
96BCB7661CB40DC500C806FE /* Material+UIImage+Blank.swift */,
96BCB7671CB40DC500C806FE /* Material+UIImage+Color.swift */,
96BCB7681CB40DC500C806FE /* Material+UIImage+Crop.swift */,
96BCB7691CB40DC500C806FE /* Material+UIImage+Network.swift */,
96BCB76A1CB40DC500C806FE /* Material+UIImage+Resize.swift */,
96BCB76B1CB40DC500C806FE /* Material+UIImage+Size.swift */,
96BCB76C1CB40DC500C806FE /* Material+UIImage.swift */,
96977DA51CBB2E49000BEFC4 /* Material+UIImage+FilterBlur.swift */,
9679CEAA1CC69E080021685B /* Material+UIImage+TintColor.swift */,
);
name = Extension;
sourceTree = "<group>";
......@@ -693,12 +666,6 @@
96BCB8271CB4115200C806FE /* Material+Obj-C.swift in Headers */,
96BCB8281CB4115200C806FE /* Material+String.swift in Headers */,
96BCB8291CB4115200C806FE /* Material+UIFont.swift in Headers */,
96BCB82A1CB4115200C806FE /* Material+UIImage+Blank.swift in Headers */,
96BCB82B1CB4115200C806FE /* Material+UIImage+Color.swift in Headers */,
96BCB82C1CB4115200C806FE /* Material+UIImage+Crop.swift in Headers */,
96BCB82D1CB4115200C806FE /* Material+UIImage+Network.swift in Headers */,
96BCB82E1CB4115200C806FE /* Material+UIImage+Resize.swift in Headers */,
96BCB82F1CB4115200C806FE /* Material+UIImage+Size.swift in Headers */,
96BCB8301CB4115200C806FE /* Material+UIImage.swift in Headers */,
96BCB8311CB4115200C806FE /* Font.swift in Headers */,
96BCB8321CB4115200C806FE /* RobotoFont.swift in Headers */,
......@@ -923,7 +890,6 @@
files = (
96BCB7C01CB40DC500C806FE /* MaterialDataSourceItem.swift in Sources */,
96BCB7AC1CB40DC500C806FE /* Material+Obj-C.swift in Sources */,
9679CEAB1CC69E080021685B /* Material+UIImage+TintColor.swift in Sources */,
9658F2171CD6FA4700B902C1 /* IconButton.swift in Sources */,
96BCB7BB1CB40DC500C806FE /* MaterialCollectionViewCell.swift in Sources */,
96BCB7CF1CB40DC500C806FE /* Shape.swift in Sources */,
......@@ -933,7 +899,6 @@
96BCB7D61CB40DC500C806FE /* Menu.swift in Sources */,
96BCB7E61CB40DC500C806FE /* TextStorage.swift in Sources */,
968C99451D37730B000074FF /* Direction.swift in Sources */,
96BCB7B21CB40DC500C806FE /* Material+UIImage+Network.swift in Sources */,
96BCB7A91CB40DC500C806FE /* FlatButton.swift in Sources */,
96BCB7CA1CB40DC500C806FE /* Layout.swift in Sources */,
96BCB7D11CB40DC500C806FE /* Switch.swift in Sources */,
......@@ -950,12 +915,9 @@
96BCB7A21CB40DC500C806FE /* BottomTabBar.swift in Sources */,
96BCB7BD1CB40DC500C806FE /* MaterialCollectionViewDelegate.swift in Sources */,
961F18E81CD93E3E008927C5 /* ErrorTextField.swift in Sources */,
96BCB7AF1CB40DC500C806FE /* Material+UIImage+Blank.swift in Sources */,
96BCB7D01CB40DC500C806FE /* InterimSpace.swift in Sources */,
96BCB7B31CB40DC500C806FE /* Material+UIImage+Resize.swift in Sources */,
96BCB7E81CB40DC500C806FE /* Toolbar.swift in Sources */,
96BCB7C41CB40DC500C806FE /* Font.swift in Sources */,
96BCB7B41CB40DC500C806FE /* Material+UIImage+Size.swift in Sources */,
96BCB7AA1CB40DC500C806FE /* Grid.swift in Sources */,
96BCB7E71CB40DC500C806FE /* TextView.swift in Sources */,
96BCB7C31CB40DC500C806FE /* EdgeInsets.swift in Sources */,
......@@ -971,7 +933,6 @@
968C99471D377849000074FF /* Offset.swift in Sources */,
96BCB7D51CB40DC500C806FE /* View.swift in Sources */,
96BCB7DE1CB40DC500C806FE /* SearchBar.swift in Sources */,
96BCB7B11CB40DC500C806FE /* Material+UIImage+Crop.swift in Sources */,
96BCB7B81CB40DC500C806FE /* Border.swift in Sources */,
96BCB7A61CB40DC500C806FE /* Card.swift in Sources */,
96BCB7C91CB40DC500C806FE /* Layer.swift in Sources */,
......@@ -988,7 +949,6 @@
96BCB7E01CB40DC500C806FE /* NavigationDrawerController.swift in Sources */,
96BCB7AD1CB40DC500C806FE /* Material+String.swift in Sources */,
96BCB7A51CB40DC500C806FE /* Capture.swift in Sources */,
96BCB7B01CB40DC500C806FE /* Material+UIImage+Color.swift in Sources */,
96BCB7B91CB40DC500C806FE /* Button.swift in Sources */,
96BCB7B51CB40DC500C806FE /* Material+UIImage.swift in Sources */,
96BCB7E31CB40DC500C806FE /* TabBar.swift in Sources */,
......
......@@ -69,7 +69,7 @@ public struct Animation {
let delayed: AnimationDelayCancelBlock = { (cancel: Bool) in
if !cancel {
DispatchQueue.main.asynchronously(execute: completion)
DispatchQueue.main.async(execute: completion)
}
cancelable = nil
}
......
......@@ -67,6 +67,6 @@ public class BarView : ControlView {
*/
public override func prepareView() {
super.prepareView()
depth = .depth1
depthPreset = .depth1
}
}
......@@ -31,15 +31,15 @@
import UIKit
public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControllerAnimatedTransitioning {
public func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let fromView : UIView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
let toView : UIView = transitionContext.viewForKey(UITransitionContextToViewKey)!
public func animateTransition(_ transitionContext: UIViewControllerContextTransitioning) {
let fromView : UIView = transitionContext.view(forKey: UITransitionContextFromViewKey)!
let toView : UIView = transitionContext.view(forKey: UITransitionContextToViewKey)!
toView.alpha = 0
transitionContext.containerView()!.addSubview(fromView)
transitionContext.containerView()!.addSubview(toView)
transitionContext.containerView().addSubview(fromView)
transitionContext.containerView().addSubview(toView)
UIView.animateWithDuration(transitionDuration(transitionContext),
UIView.animate(withDuration: transitionDuration(transitionContext),
animations: { _ in
toView.alpha = 1
fromView.alpha = 0
......@@ -48,20 +48,20 @@ public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControl
}
}
public func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
public func transitionDuration(_ transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.35
}
}
public enum BottomNavigationTransitionAnimation {
case None
case Fade
case none
case fade
}
@IBDesignable
public class BottomNavigationController : UITabBarController, UITabBarControllerDelegate {
/// The transition animation to use when selecting a new tab.
public var transitionAnimation: BottomNavigationTransitionAnimation = .Fade
public var transitionAnimation: BottomNavigationTransitionAnimation = .fade
/**
An initializer that initializes the object with a NSCoder object.
......@@ -76,7 +76,7 @@ public class BottomNavigationController : UITabBarController, UITabBarController
- Parameter nibNameOrNil: An Optional String for the nib.
- Parameter bundle: An Optional NSBundle where the nib is located.
*/
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
......@@ -134,19 +134,19 @@ public class BottomNavigationController : UITabBarController, UITabBarController
}
/// Handles transitions when tabBarItems are pressed.
public func tabBarController(tabBarController: UITabBarController, animationControllerForTransitionFromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
public func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let fVC: UIViewController? = fromVC
let tVC: UIViewController? = toVC
if nil == fVC || nil == tVC {
return nil
}
return .Fade == transitionAnimation ? BottomNavigationFadeAnimatedTransitioning() : nil
return .fade == transitionAnimation ? BottomNavigationFadeAnimatedTransitioning() : nil
}
/// Prepares the tabBar.
private func prepareTabBar() {
tabBar.depth = .depth1
let image: UIImage? = UIImage.imageWithColor(Color.clear, size: CGSizeMake(1, 1))
tabBar.depthPreset = .depth1
let image = UIImage.imageWithColor(color: Color.clear, size: CGSize(width: 1, height: 1))
tabBar.shadowImage = image
tabBar.backgroundImage = image
tabBar.backgroundColor = Color.white
......
......@@ -115,6 +115,11 @@ public class BottomTabBar: UITabBar {
self.init(frame: CGRect.zero)
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
public override func layoutSubviews() {
super.layoutSubviews()
if let v: Array<UITabBarItem> = items {
......
......@@ -164,7 +164,7 @@ public class Button: UIButton {
*/
@IBInspectable public var contentInset = EdgeInsets.zero {
didSet {
contentEdgeInsets = contentInset.asEdgeInsets
contentEdgeInsets = contentInset
}
}
......
......@@ -47,7 +47,7 @@ public class ControlView : View {
}
/// A wrapper around grid.contentInset.
@IBInspectable public var contentInset: Inset {
@IBInspectable public var contentInset: EdgeInsets {
get {
return grid.contentInset
}
......@@ -152,7 +152,7 @@ public class ControlView : View {
public init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
super.init(frame: CGRect.zero)
frame.size = intrinsicContentSize()
prepareProperties(leftControls, rightControls: rightControls)
prepareProperties(leftControls: leftControls, rightControls: rightControls)
}
public override func layoutSubviews() {
......@@ -214,7 +214,7 @@ public class ControlView : View {
}
public override func intrinsicContentSize() -> CGSize {
return CGSizeMake(width, 44)
return CGSize(width: width, height: 44)
}
/**
......@@ -227,8 +227,8 @@ public class ControlView : View {
public override func prepareView() {
super.prepareView()
interimSpacePreset = .interimSpace1
contentEdgeInsetsPreset = .Square1
autoresizingMask = .FlexibleWidth
contentEdgeInsetsPreset = .square1
autoresizingMask = .flexibleWidth
shadowPathAutoSizeEnabled = false
prepareContentView()
}
......
......@@ -50,7 +50,7 @@ public struct Depth {
public var radius: CGFloat
/// Preset.
public var preset: DepthPreset {
public var preset: DepthPreset = .none {
didSet {
let depth = DepthPresetToValue(preset: preset)
offset = depth.offset
......@@ -76,6 +76,7 @@ public struct Depth {
- Parameter preset: DepthPreset.
*/
public init(preset: DepthPreset) {
self.init()
self.preset = preset
}
......
......@@ -30,7 +30,7 @@
import UIKit
public class ErrorTextField : TextField {
public class ErrorTextField: TextField {
/// Controls the visibility of detailLabel
@IBInspectable public var revealError: Bool = false {
didSet {
......
......@@ -150,7 +150,7 @@ public class Grid {
}
/// Insets value for grid.
public var contentInset: Inset = EdgeInsetsPresetToValue(preset: .none) {
public var contentInset: EdgeInsets = EdgeInsetsPresetToValue(preset: .none) {
didSet {
reload()
}
......
......@@ -32,26 +32,29 @@ import UIKit
public struct Icon {
/// An internal reference to the icons bundle.
private static var internalBundle: NSBundle?
private static var internalBundle: Bundle?
/**
A public reference to the icons bundle, that aims to detect
the correct bundle to use.
*/
public static var bundle: NSBundle {
public static var bundle: Bundle {
if nil == Icon.internalBundle {
Icon.internalBundle = NSBundle(forClass: View.self)
let b: NSBundle? = NSBundle(URL: Icon.internalBundle!.resourceURL!.URLByAppendingPathComponent("io.cosmicmind.material.icons.bundle"))
if let v: NSBundle = b {
Icon.internalBundle = Bundle(for: View.self)
let url = Icon.internalBundle!.resourceURL!
do {
let b = Bundle(url: try url.appendingPathComponent("io.cosmicmind.material.icons.bundle"))
if let v = b {
Icon.internalBundle = v
}
} catch {}
}
return Icon.internalBundle!
}
/// Get the icon by the file name.
public static func icon(name: String) -> UIImage? {
return UIImage(named: name, inBundle: bundle, compatibleWithTraitCollection: nil)?.imageWithRenderingMode(.AlwaysTemplate)
public static func icon(_ name: String) -> UIImage? {
return UIImage(named: name, in: bundle, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate)
}
/// Google icons.
......
......@@ -286,52 +286,43 @@ public class Layer: CAShapeLayer {
}
/**
A method that accepts CAAnimation objects and executes.
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
- Parameter animation: A CAAnimation instance.
*/
public func animate(animation: CAAnimation) {
animation.delegate = self
if let a: CABasicAnimation = animation as? CABasicAnimation {
if let a = animation as? CABasicAnimation {
a.fromValue = (nil == presentation() ? self : presentation()!).value(forKeyPath: a.keyPath!)
}
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
if let a = animation as? CAPropertyAnimation {
add(a, forKey: a.keyPath!)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
} else if let a = animation as? CAAnimationGroup {
add(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition {
} else if let a = animation as? CATransition {
add(a, forKey: kCATransition)
}
}
/**
A delegation method that is executed when the layer starts
A delegation method that is executed when the backing layer stops
running an animation.
- Parameter animation: The currently running CAAnimation instance.
*/
public override func animationDidStart(_ animation: CAAnimation) {
(delegate as? AnimationDelegate)?.materialAnimationDidStart?(animation: animation)
}
/**
A delegation method that is executed when the layer stops
running an animation.
- Parameter anim: The CAAnimation instance that stopped running.
- Parameter animation: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false
if interrupted.
*/
public override func animationDidStop(_ animation: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation {
if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
if let a = animation as? CAPropertyAnimation {
if let b = a as? CABasicAnimation {
if let v = b.toValue {
if let k = b.keyPath {
setValue(v, forKeyPath: k)
removeAnimation(forKey: k)
}
}
}
(delegate as? AnimationDelegate)?.materialAnimationDidStop?(animation: animation, finished: flag)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
} else if let a = animation as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
......@@ -340,7 +331,7 @@ public class Layer: CAShapeLayer {
/// Prepares the visualLayer property.
public func prepareVisualLayer() {
visualLayer = CAShapeLayer(Z
visualLayer = CAShapeLayer()
visualLayer.zPosition = 0
visualLayer.masksToBounds = true
addSublayer(visualLayer)
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* 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
public extension String {
/**
:name: lines
*/
public var lines: Array<String> {
return componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet())
}
/**
:name: firstLine
*/
public var firstLine: String? {
return lines.first?.trim()
}
/**
:name: lastLine
*/
public var lastLine: String? {
return lines.last?.trim()
}
/**
:name: replaceNewLineCharater
*/
public func replaceNewLineCharater(replace: String = " ") -> String {
return componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).joinWithSeparator(replace).trim()
}
/**
:name: replacePunctuationCharacters
*/
public func replacePunctuationCharacters(replace: String = "") -> String {
return componentsSeparatedByCharactersInSet(NSCharacterSet.punctuationCharacterSet()).joinWithSeparator(replace).trim()
}
/**
:name: trim
*/
public func trim() -> String {
return stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
}
}
///*
//* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
//* 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
//
//public extension String {
// /**
// :name: lines
// */
// public var lines: Array<String> {
// return componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet())
// }
//
// /**
// :name: firstLine
// */
// public var firstLine: String? {
// return lines.first?.trim()
// }
//
// /**
// :name: lastLine
// */
// public var lastLine: String? {
// return lines.last?.trim()
// }
//
// /**
// :name: replaceNewLineCharater
// */
// public func replaceNewLineCharater(replace: String = " ") -> String {
// return componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).joinWithSeparator(replace).trim()
// }
//
// /**
// :name: replacePunctuationCharacters
// */
// public func replacePunctuationCharacters(replace: String = "") -> String {
// return componentsSeparatedByCharactersInSet(NSCharacterSet.punctuationCharacterSet()).joinWithSeparator(replace).trim()
// }
//
// /**
// :name: trim
// */
// public func trim() -> String {
// return stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
// }
//}
......@@ -35,8 +35,8 @@ public extension UIFont {
:name: stringSize
*/
public func stringSize(string: String, constrainedToWidth width: Double) -> CGSize {
return string.boundingRectWithSize(CGSize(width: width, height: DBL_MAX),
options: NSStringDrawingOptions.UsesLineFragmentOrigin,
return string.boundingRect(with: CGSize(width: width, height: DBL_MAX),
options: NSStringDrawingOptions.usesLineFragmentOrigin,
attributes: [NSFontAttributeName: self],
context: nil).size
}
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* 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
public extension UIImage {
/**
Creates an clear image.
- Returns: A UIImage that is clear.
*/
public class func clearImage() -> UIImage {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36, 36), false, 0)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* 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
public extension UIImage {
/**
Creates an Image that is a color.
- Parameter color: The UIColor to create the image from.
- Parameter size: The size of the image to create.
- Returns: A UIImage that is the color passed in.
*/
public class func imageWithColor(color: UIColor, size: CGSize) -> UIImage {
let rect = CGRectMake(0, 0, size.width, size.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
color.setFill()
UIRectFill(rect)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* 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
public extension UIImage {
/**
:name: crop
*/
public func crop(toWidth tw: CGFloat, toHeight th: CGFloat) -> UIImage? {
let g: UIImage?
let b: Bool = width > height
let s: CGFloat = b ? th / height : tw / width
let t: CGSize = CGSizeMake(tw, th)
let w = width * s
let h = height * s
UIGraphicsBeginImageContext(t)
drawInRect(b ? CGRectMake(-1 * (w - t.width) / 2, 0, w, h) : CGRectMake(0, -1 * (h - t.height) / 2, w, h), blendMode: .Normal, alpha: 1)
g = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return g!
}
}
\ No newline at end of file
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* 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
import Accelerate
/// Creates an effect buffer for images that are already effected.
private func createEffectBuffer(context: CGContext) -> vImage_Buffer {
let data = CGBitmapContextGetData(context)
let width = vImagePixelCount(CGBitmapContextGetWidth(context))
let height = vImagePixelCount(CGBitmapContextGetHeight(context))
let rowBytes = CGBitmapContextGetBytesPerRow(context)
return vImage_Buffer(data: data, height: height, width: width, rowBytes: rowBytes)
}
public extension UIImage {
/**
Applies a blur effect to a UIImage.
- Parameter blurRadius: The radius of the blur effect.
- Parameter tintColor: The color used for the blur effect (optional).
- Parameter saturationDeltaFactor: The delta factor for the saturation of the blur effect.
- Returns: a UIImage.
*/
func filterBlur(blurRadius: CGFloat = 0, tintColor: UIColor? = nil, saturationDeltaFactor: CGFloat = 0) -> UIImage? {
var effectImage: UIImage = self
let screenScale: CGFloat = Device.scale
let imageRect: CGRect = CGRect(origin: CGPoint.zero, size: size)
let hasBlur: Bool = blurRadius > CGFloat(FLT_EPSILON)
let hasSaturationChange: Bool = fabs(saturationDeltaFactor - 1.0) > CGFloat(FLT_EPSILON)
if hasBlur || hasSaturationChange {
UIGraphicsBeginImageContextWithOptions(size, false, screenScale)
let effectInContext: CGContext = UIGraphicsGetCurrentContext()!
CGContextScaleCTM(effectInContext, 1.0, -1.0)
CGContextTranslateCTM(effectInContext, 0, -size.height)
CGContextDrawImage(effectInContext, imageRect, self.cgImage)
var effectInBuffer: vImage_Buffer = createEffectBuffer(effectInContext)
UIGraphicsBeginImageContextWithOptions(size, false, screenScale)
let effectOutContext: CGContext = UIGraphicsGetCurrentContext()!
var effectOutBuffer: vImage_Buffer = createEffectBuffer(effectOutContext)
if hasBlur {
let inputRadius: CGFloat = blurRadius * screenScale
var radius: UInt32 = UInt32(floor(inputRadius * 3.0 * CGFloat(sqrt(2 * M_PI)) / 4 + 0.5))
if 1 != radius % 2 {
radius += 1 // force radius to be odd so that the three box-blur methodology works.
}
let imageEdgeExtendFlags: UInt32 = vImage_Flags(kvImageEdgeExtend)
vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, nil, 0, 0, radius, radius, nil, imageEdgeExtendFlags)
vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, nil, 0, 0, radius, radius, nil, imageEdgeExtendFlags)
vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, nil, 0, 0, radius, radius, nil, imageEdgeExtendFlags)
}
var effectImageBuffersAreSwapped: Bool = false
if hasSaturationChange {
let s: CGFloat = saturationDeltaFactor
let floatingPointSaturationMatrix: Array<CGFloat> = [
0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
0, 0, 0, 1
]
let divisor: CGFloat = 256
let matrixSize: Int = floatingPointSaturationMatrix.count
var saturationMatrix: Array<Int16> = Array<Int16>(count: matrixSize, repeatedValue: 0)
for i: Int in 0 ..< matrixSize {
saturationMatrix[i] = Int16(round(floatingPointSaturationMatrix[i] * divisor))
}
if hasBlur {
vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, Int32(divisor), nil, nil, vImage_Flags(kvImageNoFlags))
effectImageBuffersAreSwapped = true
} else {
vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, Int32(divisor), nil, nil, vImage_Flags(kvImageNoFlags))
}
}
if !effectImageBuffersAreSwapped {
effectImage = UIGraphicsGetImageFromCurrentImageContext()
}
UIGraphicsEndImageContext()
if effectImageBuffersAreSwapped {
effectImage = UIGraphicsGetImageFromCurrentImageContext()
}
UIGraphicsEndImageContext()
}
// Set up output context.
UIGraphicsBeginImageContextWithOptions(size, false, screenScale)
let outputContext: CGContext = UIGraphicsGetCurrentContext()!
CGContextScaleCTM(outputContext, 1.0, -1.0)
CGContextTranslateCTM(outputContext, 0, -size.height)
// Draw base image.
CGContextDrawImage(outputContext, imageRect, self.cgImage)
// Draw effect image.
if hasBlur {
CGContextSaveGState(outputContext)
CGContextDrawImage(outputContext, imageRect, effectImage.cgImage)
CGContextRestoreGState(outputContext)
}
// Add in color tint.
if let v: UIColor = tintColor {
CGContextSaveGState(outputContext)
CGContextSetFillColorWithColor(outputContext, v.cgColor)
CGContextFillRect(outputContext, imageRect)
CGContextRestoreGState(outputContext)
}
// Output image is ready.
let outputImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return outputImage
}
}
///*
//* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
//* 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
//import Accelerate
//
///// Creates an effect buffer for images that are already effected.
//private func createEffectBuffer(context: CGContext) -> vImage_Buffer {
// let data = CGBitmapContextGetData(context)
// let width = vImagePixelCount(CGBitmapContextGetWidth(context))
// let height = vImagePixelCount(CGBitmapContextGetHeight(context))
// let rowBytes = CGBitmapContextGetBytesPerRow(context)
// return vImage_Buffer(data: data, height: height, width: width, rowBytes: rowBytes)
//}
//
//public extension UIImage {
// /**
// Applies a blur effect to a UIImage.
// - Parameter blurRadius: The radius of the blur effect.
// - Parameter tintColor: The color used for the blur effect (optional).
// - Parameter saturationDeltaFactor: The delta factor for the saturation of the blur effect.
// - Returns: a UIImage.
// */
// func filterBlur(blurRadius: CGFloat = 0, tintColor: UIColor? = nil, saturationDeltaFactor: CGFloat = 0) -> UIImage? {
// var effectImage: UIImage = self
//
// let screenScale: CGFloat = Device.scale
// let imageRect: CGRect = CGRect(origin: CGPoint.zero, size: size)
// let hasBlur: Bool = blurRadius > CGFloat(FLT_EPSILON)
// let hasSaturationChange: Bool = fabs(saturationDeltaFactor - 1.0) > CGFloat(FLT_EPSILON)
//
// if hasBlur || hasSaturationChange {
// UIGraphicsBeginImageContextWithOptions(size, false, screenScale)
// let effectInContext: CGContext = UIGraphicsGetCurrentContext()!
// CGContextScaleCTM(effectInContext, 1.0, -1.0)
// CGContextTranslateCTM(effectInContext, 0, -size.height)
// CGContextDrawImage(effectInContext, imageRect, self.cgImage)
// var effectInBuffer: vImage_Buffer = createEffectBuffer(effectInContext)
//
// UIGraphicsBeginImageContextWithOptions(size, false, screenScale)
// let effectOutContext: CGContext = UIGraphicsGetCurrentContext()!
// var effectOutBuffer: vImage_Buffer = createEffectBuffer(effectOutContext)
//
// if hasBlur {
// let inputRadius: CGFloat = blurRadius * screenScale
// var radius: UInt32 = UInt32(floor(inputRadius * 3.0 * CGFloat(sqrt(2 * M_PI)) / 4 + 0.5))
// if 1 != radius % 2 {
// radius += 1 // force radius to be odd so that the three box-blur methodology works.
// }
//
// let imageEdgeExtendFlags: UInt32 = vImage_Flags(kvImageEdgeExtend)
//
// vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, nil, 0, 0, radius, radius, nil, imageEdgeExtendFlags)
// vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, nil, 0, 0, radius, radius, nil, imageEdgeExtendFlags)
// vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, nil, 0, 0, radius, radius, nil, imageEdgeExtendFlags)
// }
//
// var effectImageBuffersAreSwapped: Bool = false
//
// if hasSaturationChange {
// let s: CGFloat = saturationDeltaFactor
// let floatingPointSaturationMatrix: Array<CGFloat> = [
// 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0,
// 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0,
// 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0,
// 0, 0, 0, 1
// ]
//
// let divisor: CGFloat = 256
// let matrixSize: Int = floatingPointSaturationMatrix.count
// var saturationMatrix: Array<Int16> = Array<Int16>(count: matrixSize, repeatedValue: 0)
//
// for i: Int in 0 ..< matrixSize {
// saturationMatrix[i] = Int16(round(floatingPointSaturationMatrix[i] * divisor))
// }
//
// if hasBlur {
// vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, Int32(divisor), nil, nil, vImage_Flags(kvImageNoFlags))
// effectImageBuffersAreSwapped = true
// } else {
// vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, Int32(divisor), nil, nil, vImage_Flags(kvImageNoFlags))
// }
// }
//
// if !effectImageBuffersAreSwapped {
// effectImage = UIGraphicsGetImageFromCurrentImageContext()
// }
//
// UIGraphicsEndImageContext()
//
// if effectImageBuffersAreSwapped {
// effectImage = UIGraphicsGetImageFromCurrentImageContext()
// }
//
// UIGraphicsEndImageContext()
// }
//
// // Set up output context.
// UIGraphicsBeginImageContextWithOptions(size, false, screenScale)
// let outputContext: CGContext = UIGraphicsGetCurrentContext()!
// CGContextScaleCTM(outputContext, 1.0, -1.0)
// CGContextTranslateCTM(outputContext, 0, -size.height)
//
// // Draw base image.
// CGContextDrawImage(outputContext, imageRect, self.cgImage)
//
// // Draw effect image.
// if hasBlur {
// CGContextSaveGState(outputContext)
// CGContextDrawImage(outputContext, imageRect, effectImage.cgImage)
// CGContextRestoreGState(outputContext)
// }
//
// // Add in color tint.
// if let v: UIColor = tintColor {
// CGContextSaveGState(outputContext)
// CGContextSetFillColorWithColor(outputContext, v.cgColor)
// CGContextFillRect(outputContext, imageRect)
// CGContextRestoreGState(outputContext)
// }
//
// // Output image is ready.
// let outputImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()
// UIGraphicsEndImageContext()
//
// return outputImage
// }
//}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* 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
public extension UIImage {
/**
Asynchronously load images with a completion block.
- Parameter URL: A URL destination to fetch the image from.
- Parameter completion: A completion block that is executed once the image
has been retrieved.
*/
public class func contentsOfURL(URL: NSURL, completion: ((image: UIImage?, error: NSError?) -> Void)) {
NSURLSession.sharedSession().dataTaskWithRequest(NSURLRequest(URL: URL)) { (data: NSData?, response: NSURLResponse?, error: NSError?) in
dispatch_async(dispatch_get_main_queue()) {
if let v: NSError = error {
completion(image: nil, error: v)
} else if let v: NSData = data {
completion(image: UIImage(data: v), error: nil)
}
}
}.resume()
}
}
......@@ -45,9 +45,9 @@ public extension UIImage {
}
let g: UIImage?
let t: CGRect = CGRectMake(0, 0, w ?? tw, h ?? th)
let t: CGRect = CGRect(x: 0, y: 0, width: w ?? tw, height: h ?? th)
UIGraphicsBeginImageContextWithOptions(t.size, false, Device.scale)
drawInRect(t, blendMode: .Normal, alpha: 1)
draw(in: t, blendMode: .normal, alpha: 1)
g = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* 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
public extension UIImage {
/**
:name: width
*/
public var width: CGFloat {
return size.width
}
/**
:name: height
*/
public var height: CGFloat {
return size.height
}
}
\ No newline at end of file
......@@ -30,7 +30,151 @@
import UIKit
public enum ImageFormatType {
case PNG
case JPEG
public enum ImageFormat {
case png
case jpeg
}
public extension UIImage {
/**
:name: width
*/
public var width: CGFloat {
return size.width
}
/**
:name: height
*/
public var height: CGFloat {
return size.height
}
/**
:name: internalResize
*/
private func internalResize(toWidth tw: CGFloat = 0, toHeight th: CGFloat = 0) -> UIImage? {
var w: CGFloat?
var h: CGFloat?
if 0 < tw {
h = height * tw / width
} else if 0 < th {
w = width * th / height
}
let g: UIImage?
let t: CGRect = CGRect(x: 0, y: 0, width: w ?? tw, height: h ?? th)
UIGraphicsBeginImageContextWithOptions(t.size, false, Device.scale)
draw(in: t, blendMode: .normal, alpha: 1)
g = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return g
}
/**
:name: resize
*/
public func resize(toWidth w: CGFloat) -> UIImage? {
return internalResize(toWidth: w)
}
/**
:name: resize
*/
public func resize(toHeight h: CGFloat) -> UIImage? {
return internalResize(toHeight: h)
}
/**
Creates a new image with the passed in color.
- Parameter color: The UIColor to create the image from.
- Returns: A UIImage that is the color passed in.
*/
public func tintWithColor(color: UIColor) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, Device.scale)
guard let context = UIGraphicsGetCurrentContext() else {
return nil
}
context.scale(x: 1.0, y: -1.0)
context.translate(x: 0.0, y: -size.height)
context.setBlendMode(.multiply)
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
context.clipToMask(rect, mask: cgImage!)
color.setFill()
context.fill(rect)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
/**
Creates an Image that is a color.
- Parameter color: The UIColor to create the image from.
- Parameter size: The size of the image to create.
- Returns: A UIImage that is the color passed in.
*/
public class func imageWithColor(color: UIColor, size: CGSize) -> UIImage? {
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
color.setFill()
UIRectFill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
/**
:name: crop
*/
public func crop(toWidth tw: CGFloat, toHeight th: CGFloat) -> UIImage? {
let g: UIImage?
let b: Bool = width > height
let s: CGFloat = b ? th / height : tw / width
let t: CGSize = CGSize(width: tw, height: th)
let w = width * s
let h = height * s
UIGraphicsBeginImageContext(t)
draw(in: b ? CGRect(x: -1 * (w - t.width) / 2, y: 0, width: w, height: h) : CGRect(x: 0, y: -1 * (h - t.height) / 2, width: w, height: h), blendMode: .normal, alpha: 1)
g = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return g
}
/**
Creates an clear image.
- Returns: A UIImage that is clear.
*/
public class func clear(size: CGSize = CGSize(width: 16, height: 16)) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
/**
Asynchronously load images with a completion block.
- Parameter URL: A URL destination to fetch the image from.
- Parameter completion: A completion block that is executed once the image
has been retrieved.
*/
public class func contentsOfURL(url: URL, completion: ((image: UIImage?, error: NSError?) -> Void)) {
URLSession.shared().dataTask(with: URLRequest(url: url)) { (data: Data?, response: URLResponse?, error: NSError?) in
DispatchQueue.main.async {
if let v = error {
completion(image: nil, error: v)
} else if let v = data {
completion(image: UIImage(data: v), error: nil)
}
}
}.resume()
}
}
......@@ -43,7 +43,7 @@ public class Material {
}
/// A property that sets the cornerRadius of the backing layer.
public var cornerRadiusPreset: CornerRadiusPreset {
public var cornerRadiusPreset: CornerRadiusPreset = .none {
didSet {
guard let v = view else {
return
......@@ -56,7 +56,7 @@ public class Material {
}
/// A preset property to set the borderWidth.
public var borderWidthPreset: BorderWidthPreset {
public var borderWidthPreset: BorderWidthPreset = .none {
didSet {
guard let v = view else {
return
......@@ -79,7 +79,7 @@ public class Material {
}
/// Grid reference.
public var depth: Depth {
public var depth: Depth = Depth.zero {
didSet {
guard let v = view else {
return
......@@ -98,7 +98,7 @@ private var MaterialKey: UInt8 = 0
/// Grid extension for UIView.
public extension UIView {
/// Material Reference.
private var material: Material {
internal var material: Material {
get {
return AssociatedObject(base: self, key: &MaterialKey) {
return Material(view: self)
......
......@@ -264,8 +264,6 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
depthPreset = .none
cornerRadiusPreset = .none
contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder)
prepareView()
......@@ -278,8 +276,6 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
- Parameter frame: A CGRect instance.
*/
public override init(frame: CGRect) {
depthPreset = .none
cornerRadiusPreset = .none
contentsGravityPreset = .ResizeAspectFill
super.init(frame: frame)
prepareView()
......
......@@ -264,7 +264,6 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
cornerRadiusPreset = .none
shape = .none
contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder)
......@@ -278,7 +277,6 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
- Parameter frame: A CGRect instance.
*/
public override init(frame: CGRect) {
cornerRadiusPreset = .none
shape = .none
contentsGravityPreset = .ResizeAspectFill
super.init(frame: frame)
......
......@@ -77,53 +77,53 @@ public class MaterialCollectionViewLayout: UICollectionViewLayout {
public func indexPathsOfItemsInRect(rect: CGRect) -> Array<NSIndexPath> {
var paths: Array<NSIndexPath> = Array<NSIndexPath>()
for (attribute, indexPath) in layoutItems {
if CGRectIntersectsRect(rect, attribute.frame) {
if rect.intersects(attribute.frame) {
paths.append(indexPath)
}
}
return paths
}
public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
let item: MaterialDataSourceItem = dataSourceItems![indexPath.item]
public override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
let item: MaterialDataSourceItem = dataSourceItems![indexPath.item!]
if 0 < itemSize.width && 0 < itemSize.height {
attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, itemSize.height - contentInset.top - contentInset.bottom)
} else if .Vertical == scrollDirection {
attributes.frame = CGRectMake(contentInset.left, offset.y, collectionView!.bounds.width - contentInset.left - contentInset.right, nil == item.height ? collectionView!.bounds.height : item.height!)
attributes.frame = CGRect(x: offset.x, y: offset.y, width: itemSize.width - contentInset.left - contentInset.right, height: itemSize.height - contentInset.top - contentInset.bottom)
} else if .vertical == scrollDirection {
attributes.frame = CGRect(x: contentInset.left, y: offset.y, width: collectionView!.bounds.width - contentInset.left - contentInset.right, height: item.height ?? collectionView!.bounds.height)
} else {
attributes.frame = CGRectMake(offset.x, contentInset.top, nil == item.width ? collectionView!.bounds.width : item.width!, collectionView!.bounds.height - contentInset.top - contentInset.bottom)
attributes.frame = CGRect(x: offset.x, y: contentInset.top, width: item.width ?? collectionView!.bounds.width, height: collectionView!.bounds.height - contentInset.top - contentInset.bottom)
}
return attributes
}
public override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
public override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var layoutAttributes: Array<UICollectionViewLayoutAttributes> = Array<UICollectionViewLayoutAttributes>()
for (attribute, _) in layoutItems {
if CGRectIntersectsRect(rect, attribute.frame) {
if rect.intersects(attribute.frame) {
layoutAttributes.append(attribute)
}
}
return layoutAttributes
}
public override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
return .Vertical == scrollDirection ? newBounds.width != collectionView!.bounds.width : newBounds.height != collectionView!.bounds.height
public override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
return .vertical == scrollDirection ? newBounds.width != collectionView!.bounds.width : newBounds.height != collectionView!.bounds.height
}
public override func collectionViewContentSize() -> CGSize {
return contentSize
}
public override func prepareLayout() {
public override func prepare() {
if let dataSource: MaterialCollectionViewDataSource = collectionView?.dataSource as? MaterialCollectionViewDataSource {
prepareLayoutForItems(dataSource.items())
prepareLayoutForItems(dataSourceItems: dataSource.items())
}
}
public override func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint) -> CGPoint {
public override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
return proposedContentOffset
}
......@@ -134,12 +134,10 @@ public class MaterialCollectionViewLayout: UICollectionViewLayout {
offset.x = contentInset.left
offset.y = contentInset.top
var indexPath: NSIndexPath?
for i in 0..<dataSourceItems.count {
let item: MaterialDataSourceItem = dataSourceItems[i]
indexPath = NSIndexPath(forItem: i, inSection: 0)
layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!))
let indexPath = IndexPath(item: i, section: 0)
layoutItems.append((layoutAttributesForItem(at: indexPath)!, indexPath))
offset.x += interimSpace
offset.x += nil == item.width ? itemSize.width : item.width!
......@@ -152,11 +150,11 @@ public class MaterialCollectionViewLayout: UICollectionViewLayout {
offset.y += contentInset.bottom - interimSpace
if 0 < itemSize.width && 0 < itemSize.height {
contentSize = CGSizeMake(offset.x, offset.y)
} else if .Vertical == scrollDirection {
contentSize = CGSizeMake(collectionView!.bounds.width, offset.y)
contentSize = CGSize(width: offset.x, height: offset.y)
} else if .vertical == scrollDirection {
contentSize = CGSize(width: collectionView!.bounds.width, height: offset.y)
} else {
contentSize = CGSizeMake(offset.x, collectionView!.bounds.height)
contentSize = CGSize(width: offset.x, height: collectionView!.bounds.height)
}
}
}
......@@ -87,7 +87,7 @@ public class MaterialLabel : UILabel {
*/
@IBInspectable public var wrapped: Bool {
didSet {
textLayer.wrapped = wrapped
textLayer.isWrapped = wrapped
}
}
......@@ -148,6 +148,6 @@ public class MaterialLabel : UILabel {
*/
public func prepareView() {
contentScaleFactor = Device.scale
textAlignment = .Left
textAlignment = .left
}
}
......@@ -240,12 +240,12 @@ public class MaterialTableViewCell: UITableViewCell {
/// Sets the shadow path.
internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled {
if .none == depth {
if .none == depthPreset {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(Animation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
}
}
......
......@@ -37,7 +37,7 @@ public class MaterialTextLayer : CATextLayer {
public var fontType: UIFont? {
didSet {
if let v: UIFont = fontType {
super.font = CGFontCreateWithFontName(v.fontName as CFStringRef)!
super.font = CGFont(v.fontName as CFString)!
pointSize = v.pointSize
}
}
......@@ -73,18 +73,18 @@ public class MaterialTextLayer : CATextLayer {
/**
:name: textAlignment
*/
public var textAlignment: NSTextAlignment = .Left {
public var textAlignment: NSTextAlignment = .left {
didSet {
switch textAlignment {
case .Left:
case .left:
alignmentMode = kCAAlignmentLeft
case .Center:
case .center:
alignmentMode = kCAAlignmentCenter
case .Right:
case .right:
alignmentMode = kCAAlignmentRight
case .Justified:
case .justified:
alignmentMode = kCAAlignmentJustified
case .Natural:
case .natural:
alignmentMode = kCAAlignmentNatural
}
}
......@@ -93,20 +93,20 @@ public class MaterialTextLayer : CATextLayer {
/**
:name: lineBreakMode
*/
public var lineBreakMode: NSLineBreakMode = .ByWordWrapping {
public var lineBreakMode: NSLineBreakMode = .byWordWrapping {
didSet {
switch lineBreakMode {
case .ByWordWrapping: // Wrap at word boundaries, default
case .byWordWrapping: // Wrap at word boundaries, default
truncationMode = kCATruncationNone
case .ByCharWrapping: // Wrap at character boundaries
case .byCharWrapping: // Wrap at character boundaries
truncationMode = kCATruncationNone
case .ByClipping: // Simply clip
case .byClipping: // Simply clip
truncationMode = kCATruncationNone
case .ByTruncatingHead: // Truncate at head of line: "...wxyz"
case .byTruncatingHead: // Truncate at head of line: "...wxyz"
truncationMode = kCATruncationStart
case .ByTruncatingTail: // Truncate at tail of line: "abcd..."
case .byTruncatingTail: // Truncate at tail of line: "abcd..."
truncationMode = kCATruncationEnd
case .ByTruncatingMiddle: // Truncate middle of line: "ab...yz"
case .byTruncatingMiddle: // Truncate middle of line: "ab...yz"
truncationMode = kCATruncationMiddle
}
}
......@@ -196,9 +196,9 @@ public class MaterialTextLayer : CATextLayer {
:name: stringSize
*/
public func stringSize(constrainedToWidth width: Double) -> CGSize {
if let v: UIFont = fontType {
if let v = fontType {
if 0 < text?.utf16.count {
return v.stringSize(text!, constrainedToWidth: width)
return v.stringSize(string: text!, constrainedToWidth: width)
}
}
return CGSize.zero
......@@ -209,9 +209,9 @@ public class MaterialTextLayer : CATextLayer {
*/
internal func prepareLayer() {
textColor = Color.black
textAlignment = .Left
wrapped = true
textAlignment = .left
isWrapped = true
contentsScale = Device.scale
lineBreakMode = .ByWordWrapping
lineBreakMode = .byWordWrapping
}
}
......@@ -42,7 +42,7 @@ public extension UIViewController {
if viewController is MenuController {
return viewController as? MenuController
}
viewController = viewController?.parentViewController
viewController = viewController?.parent
}
return nil
}
......@@ -62,7 +62,7 @@ public class MenuController : RootController {
if true == isUserInteractionEnabled {
isUserInteractionEnabled = false
rootViewController.view.alpha = 0.5
menuView.open(completion)
menuView.open(completion: completion)
}
}
......@@ -74,7 +74,7 @@ public class MenuController : RootController {
public func closeMenu(completion: (() -> Void)? = nil) {
if false == isUserInteractionEnabled {
rootViewController.view.alpha = 1
menuView.close({ [weak self] in
menuView.close(completion: { [weak self] in
self?.isUserInteractionEnabled = true
completion?()
})
......
......@@ -33,6 +33,7 @@ import UIKit
@objc(MenuViewDelegate)
public protocol MenuViewDelegate : MaterialDelegate {
/// Gets called when the user taps outside menu buttons.
@objc
optional func menuViewDidTapOutside(menuView: MenuView)
}
......@@ -89,26 +90,26 @@ public class MenuView : PulseView {
}
}
public override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
/**
Since the subviews will be outside the bounds of this view,
we need to look at the subviews to see if we have a hit.
*/
guard !hidden else {
guard !isHidden else {
return nil
}
for v in subviews {
let p: CGPoint = v.convertPoint(point, fromView: self)
if CGRectContainsPoint(v.bounds, p) {
return v.hitTest(p, withEvent: event)
let p = v.convert(point, from: self)
if v.bounds.contains(p) {
return v.hitTest(p, with: event)
}
}
if menu.opened {
(delegate as? MenuViewDelegate)?.menuViewDidTapOutside?(self)
if menu.isOpened {
(delegate as? MenuViewDelegate)?.menuViewDidTapOutside?(menuView: self)
}
return super.hitTest(point, withEvent: event)
return super.hitTest(point, with: event)
}
}
......@@ -69,7 +69,7 @@ public class NavigationBar : UINavigationBar {
}
/// A wrapper around grid.contentInset.
@IBInspectable public var contentInset: Insets = EdgeInsets.zero {
@IBInspectable public var contentInset: EdgeInsets = EdgeInsets.zero {
didSet {
layoutSubviews()
}
......@@ -205,25 +205,25 @@ public class NavigationBar : UINavigationBar {
}
}
public override func sizeThatFits(size: CGSize) -> CGSize {
public override func sizeThatFits(_ size: CGSize) -> CGSize {
return intrinsicContentSize()
}
public override func layoutSubviews() {
super.layoutSubviews()
if let v: UINavigationItem = topItem {
layoutNavigationItem(v)
if let v = topItem {
layoutNavigationItem(item: v)
}
if let v: UINavigationItem = backItem {
layoutNavigationItem(v)
if let v = backItem {
layoutNavigationItem(item: v)
}
}
public override func pushNavigationItem(item: UINavigationItem, animated: Bool) {
super.pushNavigationItem(item, animated: animated)
layoutNavigationItem(item)
public override func pushItem(_ item: UINavigationItem, animated: Bool) {
super.pushItem(item, animated: animated)
layoutNavigationItem(item: item)
}
/**
......@@ -232,10 +232,11 @@ public class NavigationBar : UINavigationBar {
*/
internal func layoutNavigationItem(item: UINavigationItem) {
if willRenderView {
prepareItem(item)
prepareItem(item: item)
let titleView = prepareTitleView(item: item)
let contentView = prepareContentView(item: item)
if let titleView: UIView = prepareTitleView(item) {
if let contentView: UIView = prepareContentView(item) {
if let g: Int = Int(width / gridFactor) {
let columns: Int = g + 1
......@@ -325,8 +326,6 @@ public class NavigationBar : UINavigationBar {
}
}
}
}
}
/**
Prepares the view instance when intialized. When subclassing,
......@@ -336,16 +335,16 @@ public class NavigationBar : UINavigationBar {
when subclassing.
*/
public func prepareView() {
barStyle = .Black
translucent = false
depth = .depth1
barStyle = .black
isTranslucent = false
depthPreset = .depth1
interimSpacePreset = .interimSpace1
contentEdgeInsetsPreset = .Square1
contentEdgeInsetsPreset = .square1
contentScaleFactor = Device.scale
backButtonImage = Icon.cm.arrowBack
let image: UIImage? = UIImage.imageWithColor(Color.clear, size: CGSizeMake(1, 1))
let image: UIImage? = UIImage.imageWithColor(color: Color.clear, size: CGSize(width: 1, height: 1))
shadowImage = image
setBackgroundImage(image, forBarMetrics: .Default)
setBackgroundImage(image, for: .default)
backgroundColor = Color.white
}
......@@ -379,7 +378,7 @@ public class NavigationBar : UINavigationBar {
if nil == item.contentView {
item.contentView = UIView(frame: CGRect.zero)
}
item.contentView!.grid.axis.direction = .Vertical
item.contentView!.grid.axis.direction = .vertical
return item.contentView!
}
}
......@@ -45,7 +45,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
- Parameter nibNameOrNil: An Optional String for the nib.
- Parameter bundle: An Optional NSBundle where the nib is located.
*/
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
......@@ -58,15 +58,15 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
setViewControllers([rootViewController], animated: false)
}
public override func viewWillAppear(animated: Bool) {
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let v: UIGestureRecognizer = interactivePopGestureRecognizer {
if let x: NavigationDrawerController = navigationDrawerController {
if let l: UIPanGestureRecognizer = x.leftPanGesture {
l.requireGestureRecognizerToFail(v)
l.require(toFail: v)
}
if let r: UIPanGestureRecognizer = x.rightPanGesture {
r.requireGestureRecognizerToFail(v)
r.require(toFail: v)
}
}
}
......@@ -77,12 +77,12 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
prepareView()
}
public override func viewDidAppear(animated: Bool) {
public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Load the initial topItem.
if let v: NavigationBar = navigationBar as? NavigationBar {
if let item: UINavigationItem = v.topItem {
v.layoutNavigationItem(item)
v.layoutNavigationItem(item: item)
}
}
}
......@@ -94,7 +94,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
- Parameter touch: The UITouch event.
- Returns: A Boolean of whether to continue the gesture or not, true yes, false no.
*/
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return interactivePopGestureRecognizer == gestureRecognizer && nil != navigationBar.backItem
}
......@@ -110,9 +110,8 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
if let v: NavigationBar = navigationBar as? NavigationBar {
let backButton: IconButton = IconButton()
backButton.pulseColor = Color.white
backButton.setImage(v.backButtonImage, forState: .Normal)
backButton.setImage(v.backButtonImage, forState: .Highlighted)
backButton.addTarget(self, action: #selector(handleBackButton), forControlEvents: .TouchUpInside)
backButton.setImage(v.backButtonImage, for: .highlighted)
backButton.addTarget(self, action: #selector(handleBackButton), for: .touchUpInside)
if var c: Array<UIControl> = item.leftControls {
c.append(backButton)
......@@ -122,14 +121,14 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
}
item.backButton = backButton
v.layoutNavigationItem(item)
v.layoutNavigationItem(item: item)
}
return true
}
/// Handler for the back button.
internal func handleBackButton() {
popViewControllerAnimated(true)
popViewController(animated: true)
}
/**
......@@ -145,7 +144,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
// This ensures the panning gesture is available when going back between views.
if let v: UIGestureRecognizer = interactivePopGestureRecognizer {
v.enabled = true
v.isEnabled = true
v.delegate = self
}
}
......
......@@ -31,9 +31,9 @@
import UIKit
@objc
public enum NavigationDrawerPosition : NSInteger {
case Left
case Right
public enum NavigationDrawerPosition: NSInteger {
case left
case right
}
public extension UIViewController {
......@@ -60,60 +60,69 @@ public protocol NavigationDrawerControllerDelegate {
An optional delegation method that is fired before the
NavigationDrawerController opens.
*/
@objc
optional func navigationDrawerWillOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired after the
NavigationDrawerController opened.
*/
@objc
optional func navigationDrawerDidOpen(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired before the
NavigationDrawerController closes.
*/
@objc
optional func navigationDrawerWillClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired after the
NavigationDrawerController closed.
*/
@objc
optional func navigationDrawerDidClose(navigationDrawerController: NavigationDrawerController, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
NavigationDrawerController pan gesture begins.
*/
@objc
optional func navigationDrawerPanDidBegin(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
NavigationDrawerController pan gesture changes position.
*/
@objc
optional func navigationDrawerPanDidChange(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
NavigationDrawerController pan gesture ends.
*/
@objc
optional func navigationDrawerPanDidEnd(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
NavigationDrawerController tap gesture executes.
*/
@objc
optional func navigationDrawerDidTap(navigationDrawerController: NavigationDrawerController, point: CGPoint, position: NavigationDrawerPosition)
/**
An optional delegation method that is fired when the
status bar is about to change display, hidden or not.
*/
@objc
optional func navigationDrawerStatusBarHiddenState(navigationDrawerController: NavigationDrawerController, hidden: Bool)
}
@IBDesignable
@objc(NavigationDrawerController)
public class NavigationDrawerController : RootController, UIGestureRecognizerDelegate {
public class NavigationDrawerController: RootController, UIGestureRecognizerDelegate {
/**
A CGFloat property that is used internally to track
the original (x) position of the container view when panning.
......@@ -275,7 +284,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
A DepthPreset property that is used to set the depth of the
leftView when opened.
*/
public var depthPreset = .depth1
public var depthPreset: DepthPreset = .depth1
/**
A View property that is used to hide and reveal the
......@@ -358,7 +367,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
- Parameter nibNameOrNil: An Optional String for the nib.
- Parameter bundle: An Optional NSBundle where the nib is located.
*/
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
......@@ -404,7 +413,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
if let vc: UIViewController = leftViewController {
vc.view.frame.size.width = v.width
vc.view.frame.size.height = v.height
vc.view.center = CGPointMake(v.width / 2, v.height / 2)
vc.view.center = CGPoint(x: v.width / 2, y: v.height / 2)
}
}
......@@ -415,13 +424,13 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
if let vc: UIViewController = rightViewController {
vc.view.frame.size.width = v.width
vc.view.frame.size.height = v.height
vc.view.center = CGPointMake(v.width / 2, v.height / 2)
vc.view.center = CGPoint(x: v.width / 2, y: v.height / 2)
}
}
}
public override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
public override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
// Ensures the view is hidden.
if let v: View = rightView {
v.position.x = size.width + (openedRightView ? -v.width : v.width) / 2
......@@ -452,46 +461,46 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
v.shadowPathAutoSizeEnabled = false
if hide {
UIView.animateWithDuration(duration,
UIView.animate(withDuration: duration,
animations: { [weak self] in
if let s: NavigationDrawerController = self {
if let s = self {
v.bounds.size.width = width
v.position.x = -width / 2
s.rootViewController.view.alpha = 1
}
}) { [weak self] _ in
if let s: NavigationDrawerController = self {
if let s = self {
v.shadowPathAutoSizeEnabled = true
s.layoutSubviews()
s.hideView(v)
s.hideView(container: v)
}
}
} else {
UIView.animateWithDuration(duration,
UIView.animate(withDuration: duration,
animations: { [weak self] in
if let s: NavigationDrawerController = self {
if let s = self {
v.bounds.size.width = width
v.position.x = width / 2
s.rootViewController.view.alpha = 0.5
}
}) { [weak self] _ in
if let s: NavigationDrawerController = self {
if let s = self {
v.shadowPathAutoSizeEnabled = true
s.layoutSubviews()
s.showView(v)
s.showView(container: v)
}
}
}
} else {
v.bounds.size.width = width
if hide {
hideView(v)
hideView(container: v)
v.position.x = -v.width / 2
rootViewController.view.alpha = 1
} else {
v.shadowPathAutoSizeEnabled = false
showView(v)
showView(container: v)
v.position.x = width / 2
rootViewController.view.alpha = 0.5
v.shadowPathAutoSizeEnabled = true
......@@ -526,46 +535,46 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
v.shadowPathAutoSizeEnabled = false
if hide {
UIView.animateWithDuration(duration,
UIView.animate(withDuration: duration,
animations: { [weak self] in
if let s: NavigationDrawerController = self {
if let s = self {
v.bounds.size.width = width
v.position.x = s.view.bounds.width + width / 2
s.rootViewController.view.alpha = 1
}
}) { [weak self] _ in
if let s: NavigationDrawerController = self {
if let s = self {
v.shadowPathAutoSizeEnabled = true
s.layoutSubviews()
s.hideView(v)
s.hideView(container: v)
}
}
} else {
UIView.animateWithDuration(duration,
UIView.animate(withDuration: duration,
animations: { [weak self] in
if let s: NavigationDrawerController = self {
if let s = self {
v.bounds.size.width = width
v.position.x = s.view.bounds.width - width / 2
s.rootViewController.view.alpha = 0.5
}
}) { [weak self] _ in
if let s: NavigationDrawerController = self {
if let s = self {
v.shadowPathAutoSizeEnabled = true
s.layoutSubviews()
s.showView(v)
s.showView(container: v)
}
}
}
} else {
v.bounds.size.width = width
if hide {
hideView(v)
hideView(container: v)
v.position.x = view.bounds.width + v.width / 2
rootViewController.view.alpha = 1
} else {
v.shadowPathAutoSizeEnabled = false
showView(v)
showView(container: v)
v.position.x = view.bounds.width - width / 2
rootViewController.view.alpha = 0.5
v.shadowPathAutoSizeEnabled = true
......@@ -583,7 +592,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
leftView. Defaults to 0.
*/
public func toggleLeftView(velocity: CGFloat = 0) {
openedLeftView ? closeLeftView(velocity) : openLeftView(velocity)
openedLeftView ? closeLeftView(velocity: velocity) : openLeftView(velocity: velocity)
}
/**
......@@ -594,7 +603,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
leftView. Defaults to 0.
*/
public func toggleRightView(velocity: CGFloat = 0) {
openedRightView ? closeRightView(velocity) : openRightView(velocity)
openedRightView ? closeRightView(velocity: velocity) : openRightView(velocity: velocity)
}
/**
......@@ -607,16 +616,16 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
if enabledLeftView {
if let v: View = leftView {
hideStatusBar()
showView(v)
showView(container: v)
isUserInteractionEnabled = false
delegate?.navigationDrawerWillOpen?(self, position: .Left)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
delegate?.navigationDrawerWillOpen?(navigationDrawerController: self, position: .left)
UIView.animate(withDuration: Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: {
v.position.x = v.width / 2
self.rootViewController.view.alpha = 0.5
}) { [weak self] _ in
if let s: NavigationDrawerController = self {
s.delegate?.navigationDrawerDidOpen?(s, position: .Left)
if let s = self {
s.delegate?.navigationDrawerDidOpen?(navigationDrawerController: s, position: .left)
}
}
}
......@@ -633,18 +642,18 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
if enabledRightView {
if let v: View = rightView {
hideStatusBar()
showView(v)
showView(container: v)
isUserInteractionEnabled = false
delegate?.navigationDrawerWillOpen?(self, position: .Right)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
delegate?.navigationDrawerWillOpen?(navigationDrawerController: self, position: .right)
UIView.animate(withDuration: Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [weak self] in
if let s: NavigationDrawerController = self {
if let s = self {
v.position.x = s.view.bounds.width - v.width / 2
s.rootViewController.view.alpha = 0.5
}
}) { [weak self] _ in
if let s: NavigationDrawerController = self {
s.delegate?.navigationDrawerDidOpen?(s, position: .Right)
if let s = self {
s.delegate?.navigationDrawerDidOpen?(navigationDrawerController: s, position: .right)
}
}
}
......@@ -661,18 +670,18 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
if enabledLeftView {
if let v: View = leftView {
isUserInteractionEnabled = true
delegate?.navigationDrawerWillClose?(self, position: .Left)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
delegate?.navigationDrawerWillClose?(navigationDrawerController: self, position: .left)
UIView.animate(withDuration: Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [weak self] in
if let s: NavigationDrawerController = self {
if let s = self {
v.position.x = -v.width / 2
s.rootViewController.view.alpha = 1
}
}) { [weak self] _ in
if let s: NavigationDrawerController = self {
s.hideView(v)
if let s = self {
s.hideView(container: v)
s.toggleStatusBar()
s.delegate?.navigationDrawerDidClose?(s, position: .Left)
s.delegate?.navigationDrawerDidClose?(navigationDrawerController: s, position: .left)
}
}
}
......@@ -689,18 +698,18 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
if enabledRightView {
if let v: View = rightView {
isUserInteractionEnabled = true
delegate?.navigationDrawerWillClose?(self, position: .Right)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
delegate?.navigationDrawerWillClose?(navigationDrawerController: self, position: .right)
UIView.animate(withDuration: Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [weak self] in
if let s: NavigationDrawerController = self {
if let s = self {
v.position.x = s.view.bounds.width + v.width / 2
s.rootViewController.view.alpha = 1
}
}) { [weak self] _ in
if let s: NavigationDrawerController = self {
s.hideView(v)
if let s = self {
s.hideView(container: v)
s.toggleStatusBar()
s.delegate?.navigationDrawerDidClose?(s, position: .Right)
s.delegate?.navigationDrawerDidClose?(navigationDrawerController: s, position: .right)
}
}
}
......@@ -713,11 +722,11 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
- Parameter touch: The UITouch event.
- Returns: A Boolean of whether to continue the gesture or not.
*/
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if !openedRightView && gestureRecognizer == leftPanGesture && (openedLeftView || isPointContainedWithinLeftThreshold(touch.locationInView(view))) {
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
if !openedRightView && gestureRecognizer == leftPanGesture && (openedLeftView || isPointContainedWithinLeftThreshold(point: touch.location(in: view))) {
return true
}
if !openedLeftView && gestureRecognizer == rightPanGesture && (openedRightView || isPointContainedWithinRighThreshold(touch.locationInView(view))) {
if !openedLeftView && gestureRecognizer == rightPanGesture && (openedRightView || isPointContainedWithinRighThreshold(point: touch.location(in: view))) {
return true
}
if openedLeftView && gestureRecognizer == leftTapGesture {
......@@ -735,20 +744,21 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
- Parameter recognizer: A UIPanGestureRecognizer that is
passed to the handler when recognized.
*/
@objc
internal func handleLeftViewPanGesture(recognizer: UIPanGestureRecognizer) {
if enabledLeftView && (openedLeftView || !openedRightView && isPointContainedWithinLeftThreshold(recognizer.locationInView(view))) {
if enabledLeftView && (openedLeftView || !openedRightView && isPointContainedWithinLeftThreshold(point: recognizer.location(in: view))) {
if let v: View = leftView {
let point: CGPoint = recognizer.locationInView(view)
let point: CGPoint = recognizer.location(in: view)
// Animate the panel.
switch recognizer.state {
case .Began:
case .began:
originalX = v.position.x
showView(v)
delegate?.navigationDrawerPanDidBegin?(self, point: point, position: .Left)
case .Changed:
showView(container: v)
delegate?.navigationDrawerPanDidBegin?(navigationDrawerController: self, point: point, position: .left)
case .changed:
let w: CGFloat = v.width
let translationX: CGFloat = recognizer.translationInView(v).x
let translationX: CGFloat = recognizer.translation(in: v).x
v.position.x = originalX + translationX > (w / 2) ? (w / 2) : originalX + translationX
......@@ -759,19 +769,19 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
hideStatusBar()
}
delegate?.navigationDrawerPanDidChange?(self, point: point, position: .Left)
case .Ended, .Cancelled, .Failed:
let p: CGPoint = recognizer.velocityInView(recognizer.view)
delegate?.navigationDrawerPanDidChange?(navigationDrawerController: self, point: point, position: .left)
case .ended, .cancelled, .failed:
let p: CGPoint = recognizer.velocity(in: recognizer.view)
let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.navigationDrawerPanDidEnd?(self, point: point, position: .Left)
delegate?.navigationDrawerPanDidEnd?(navigationDrawerController: self, point: point, position: .left)
if v.x <= -leftViewWidth + leftViewThreshold || x < -1000 {
closeLeftView(x)
closeLeftView(velocity: x)
} else {
openLeftView(x)
openLeftView(velocity: x)
}
case .Possible:break
case .possible:break
}
}
}
......@@ -783,20 +793,21 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
- Parameter recognizer: A UIPanGestureRecognizer that is
passed to the handler when recognized.
*/
@objc
internal func handleRightViewPanGesture(recognizer: UIPanGestureRecognizer) {
if enabledRightView && (openedRightView || !openedLeftView && isPointContainedWithinRighThreshold(recognizer.locationInView(view))) {
if enabledRightView && (openedRightView || !openedLeftView && isPointContainedWithinRighThreshold(point: recognizer.location(in: view))) {
if let v: View = rightView {
let point: CGPoint = recognizer.locationInView(view)
let point: CGPoint = recognizer.location(in: view)
// Animate the panel.
switch recognizer.state {
case .Began:
case .began:
originalX = v.position.x
showView(v)
delegate?.navigationDrawerPanDidBegin?(self, point: point, position: .Right)
case .Changed:
showView(container: v)
delegate?.navigationDrawerPanDidBegin?(navigationDrawerController: self, point: point, position: .right)
case .changed:
let w: CGFloat = v.width
let translationX: CGFloat = recognizer.translationInView(v).x
let translationX: CGFloat = recognizer.translation(in: v).x
v.position.x = originalX + translationX < view.bounds.width - (w / 2) ? view.bounds.width - (w / 2) : originalX + translationX
......@@ -807,19 +818,19 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
hideStatusBar()
}
delegate?.navigationDrawerPanDidChange?(self, point: point, position: .Right)
case .Ended, .Cancelled, .Failed:
let p: CGPoint = recognizer.velocityInView(recognizer.view)
delegate?.navigationDrawerPanDidChange?(navigationDrawerController: self, point: point, position: .right)
case .ended, .cancelled, .failed:
let p: CGPoint = recognizer.velocity(in: recognizer.view)
let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.navigationDrawerPanDidEnd?(self, point: point, position: .Right)
delegate?.navigationDrawerPanDidEnd?(navigationDrawerController: self, point: point, position: .right)
if v.x >= rightViewThreshold || x > 1000 {
closeRightView(x)
closeRightView(velocity: x)
} else {
openRightView(x)
openRightView(velocity: x)
}
case .Possible:break
case .possible:break
}
}
}
......@@ -831,11 +842,12 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
- Parameter recognizer: A UITapGestureRecognizer that is
passed to the handler when recognized.
*/
@objc
internal func handleLeftViewTapGesture(recognizer: UITapGestureRecognizer) {
if openedLeftView {
if let v: View = leftView {
delegate?.navigationDrawerDidTap?(self, point: recognizer.locationInView(view), position: .Left)
if enabledLeftView && openedLeftView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) {
delegate?.navigationDrawerDidTap?(navigationDrawerController: self, point: recognizer.location(in: view), position: .left)
if enabledLeftView && openedLeftView && !isPointContainedWithinView(container: v, point: recognizer.location(in: v)) {
closeLeftView()
}
}
......@@ -848,11 +860,12 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
- Parameter recognizer: A UITapGestureRecognizer that is
passed to the handler when recognized.
*/
@objc
internal func handleRightViewTapGesture(recognizer: UITapGestureRecognizer) {
if openedRightView {
if let v: View = rightView {
delegate?.navigationDrawerDidTap?(self, point: recognizer.locationInView(view), position: .Right)
if enabledRightView && openedRightView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) {
delegate?.navigationDrawerDidTap?(navigationDrawerController: self, point: recognizer.location(in: view), position: .right)
if enabledRightView && openedRightView && !isPointContainedWithinView(container: v, point: recognizer.location(in: v)) {
closeRightView()
}
}
......@@ -862,21 +875,21 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
/// Prepares the contentViewController.
private func prepareContentViewController() {
contentViewController.view.backgroundColor = Color.black
prepareViewControllerWithinContainer(contentViewController, container: view)
view.sendSubviewToBack(contentViewController.view)
prepareViewControllerWithinContainer(viewController: contentViewController, container: view)
view.sendSubview(toBack: contentViewController.view)
}
/// A method that prepares the leftViewController.
private func prepareLeftViewController() {
if let v: View = leftView {
prepareViewControllerWithinContainer(leftViewController, container: v)
prepareViewControllerWithinContainer(viewController: leftViewController, container: v)
}
}
/// A method that prepares the rightViewController.
private func prepareRightViewController() {
if let v: View = rightView {
prepareViewControllerWithinContainer(rightViewController, container: v)
prepareViewControllerWithinContainer(viewController: rightViewController, container: v)
}
}
......@@ -890,7 +903,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
leftViewWidth = .phone == Device.userInterfaceIdiom ? 280 : 320
leftView = View()
leftView!.frame = CGRectMake(0, 0, leftViewWidth, view.frame.height)
leftView!.frame = CGRect(x: 0, y: 0, width: leftViewWidth, height: view.frame.height)
leftView!.backgroundColor = Color.clear
view.addSubview(leftView!)
......@@ -910,7 +923,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
rightViewWidth = .phone == Device.userInterfaceIdiom ? 280 : 320
rightView = View()
rightView!.frame = CGRectMake(0, 0, rightViewWidth, view.frame.height)
rightView!.frame = CGRect(x: 0, y: 0, width: rightViewWidth, height: view.frame.height)
rightView!.backgroundColor = Color.clear
view.addSubview(rightView!)
......@@ -923,7 +936,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
/// Prepare the left pan gesture.
private func prepareLeftPanGesture() {
if nil == leftPanGesture {
leftPanGesture = UIPanGestureRecognizer(target: self, action: #selector(handleLeftViewPanGesture(_:)))
leftPanGesture = UIPanGestureRecognizer(target: self, action: #selector(handleLeftViewPanGesture(recognizer:)))
leftPanGesture!.delegate = self
view.addGestureRecognizer(leftPanGesture!)
}
......@@ -932,7 +945,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
/// Prepare the left tap gesture.
private func prepareLeftTapGesture() {
if nil == leftTapGesture {
leftTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleLeftViewTapGesture(_:)))
leftTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleLeftViewTapGesture(recognizer:)))
leftTapGesture!.delegate = self
leftTapGesture!.cancelsTouchesInView = false
view.addGestureRecognizer(leftTapGesture!)
......@@ -942,7 +955,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
/// Prepares the right pan gesture.
private func prepareRightPanGesture() {
if nil == rightPanGesture {
rightPanGesture = UIPanGestureRecognizer(target: self, action: #selector(handleRightViewPanGesture(_:)))
rightPanGesture = UIPanGestureRecognizer(target: self, action: #selector(handleRightViewPanGesture(recognizer:)))
rightPanGesture!.delegate = self
view.addGestureRecognizer(rightPanGesture!)
}
......@@ -951,7 +964,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
/// Prepares the right tap gesture.
private func prepareRightTapGesture() {
if nil == rightTapGesture {
rightTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleRightViewTapGesture(_:)))
rightTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleRightViewTapGesture(recognizer:)))
rightTapGesture!.delegate = self
rightTapGesture!.cancelsTouchesInView = false
view.addGestureRecognizer(rightTapGesture!)
......@@ -1007,14 +1020,14 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
private func showStatusBar() {
if isStatusBarHidden {
isStatusBarHidden = false
dispatch_async(dispatch_get_main_queue(), { [weak self] in
if let s: NavigationDrawerController = self {
if let v: UIWindow = UIApplication.sharedApplication().keyWindow {
DispatchQueue.main.async { [weak self] in
if let s = self {
if let v = UIApplication.shared().keyWindow {
v.windowLevel = UIWindowLevelNormal
s.delegate?.navigationDrawerStatusBarHiddenState?(s, hidden: false)
s.delegate?.navigationDrawerStatusBarHiddenState?(navigationDrawerController: s, hidden: false)
}
}
}
})
}
}
......@@ -1023,14 +1036,14 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
if enableHideStatusBar {
if !isStatusBarHidden {
isStatusBarHidden = true
dispatch_async(dispatch_get_main_queue(), { [weak self] in
if let s: NavigationDrawerController = self {
if let v: UIWindow = UIApplication.sharedApplication().keyWindow {
DispatchQueue.main.async { [weak self] in
if let s = self {
if let v = UIApplication.shared().keyWindow {
v.windowLevel = UIWindowLevelStatusBar + 1
s.delegate?.navigationDrawerStatusBarHiddenState?(s, hidden: true)
s.delegate?.navigationDrawerStatusBarHiddenState?(navigationDrawerController: s, hidden: true)
}
}
}
})
}
}
}
......@@ -1081,7 +1094,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
otherwise.
*/
private func isPointContainedWithinView(container: UIView, point: CGPoint) -> Bool {
return CGRectContainsPoint(container.bounds, point)
return container.bounds.contains(point)
}
/**
......@@ -1089,7 +1102,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
- Parameter container: A container view.
*/
private func showView(container: View) {
container.depth = depth
container.depthPreset = depthPreset
container.isHidden = false
}
......@@ -1098,7 +1111,7 @@ public class NavigationDrawerController : RootController, UIGestureRecognizerDel
- Parameter container: A container view.
*/
private func hideView(container: View) {
container.depth = .none
container.depthPreset = .none
container.isHidden = true
}
}
......@@ -67,15 +67,15 @@ public class MaterialAssociatedObjectNavigationItem {
/// Prepares the titleLabel.
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.font = RobotoFont.mediumWithSize(17)
titleLabel.textAlignment = .Center
titleLabel.font = RobotoFont.mediumWithSize(size: 17)
titleLabel.textAlignment = .center
}
/// Prepares the detailLabel.
private func prepareDetailLabel() {
detailLabel = UILabel()
detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.textAlignment = .Center
detailLabel.font = RobotoFont.regularWithSize(size: 12)
detailLabel.textAlignment = .center
}
}
......@@ -83,12 +83,12 @@ public extension UINavigationItem {
/// NavigationItem reference.
public internal(set) var item: MaterialAssociatedObjectNavigationItem {
get {
return AssociatedObject(self, key: &MaterialAssociatedObjectNavigationItemKey) {
return AssociatedObject(base: self, key: &MaterialAssociatedObjectNavigationItemKey) {
return MaterialAssociatedObjectNavigationItem()
}
}
set(value) {
AssociateObject(self, key: &MaterialAssociatedObjectNavigationItemKey, value: value)
AssociateObject(base: self, key: &MaterialAssociatedObjectNavigationItemKey, value: value)
}
}
......
......@@ -114,21 +114,21 @@ public class RootController : UIViewController {
to the toViewController has completed.
*/
public func transitionFromRootViewController(toViewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
rootViewController.willMoveToParentViewController(nil)
rootViewController.willMove(toParentViewController: nil)
addChildViewController(toViewController)
toViewController.view.frame = rootViewController.view.frame
transitionFromViewController(rootViewController,
toViewController: toViewController,
transition(from: rootViewController,
to: toViewController,
duration: duration,
options: options,
animations: animations,
completion: { [weak self] (result: Bool) in
if let s: RootController = self {
toViewController.didMoveToParentViewController(s)
toViewController.didMove(toParentViewController: s)
s.rootViewController.removeFromParentViewController()
s.rootViewController = toViewController
s.rootViewController.view.clipsToBounds = true
s.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
s.rootViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
s.rootViewController.view.contentScaleFactor = Device.scale
completion?(result)
}
......@@ -157,7 +157,7 @@ public class RootController : UIViewController {
/// A method that prepares the rootViewController.
internal func prepareRootViewController() {
prepareViewControllerWithinContainer(rootViewController, container: view)
prepareViewControllerWithinContainer(viewController: rootViewController, container: view)
}
/**
......@@ -172,9 +172,9 @@ public class RootController : UIViewController {
if let v: UIViewController = viewController {
addChildViewController(v)
container.addSubview(v.view)
v.didMoveToParentViewController(self)
v.didMove(toParentViewController: self)
v.view.clipsToBounds = true
v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
v.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
v.view.contentScaleFactor = Device.scale
}
}
......
......@@ -40,9 +40,9 @@ public class SearchBar : BarView {
/// Handle the clearButton manually.
@IBInspectable public var clearButtonAutoHandleEnabled: Bool = true {
didSet {
clearButton.removeTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
clearButton.removeTarget(self, action: #selector(handleClearButton), for: .touchUpInside)
if clearButtonAutoHandleEnabled {
clearButton.addTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside)
clearButton.addTarget(self, action: #selector(handleClearButton), for: .touchUpInside)
}
}
}
......@@ -71,7 +71,7 @@ public class SearchBar : BarView {
@IBInspectable public var placeholder: String? {
didSet {
if let v: String = placeholder {
textField.attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
textField.attributedPlaceholder = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
}
}
}
......@@ -80,7 +80,7 @@ public class SearchBar : BarView {
@IBInspectable public var placeholderColor: UIColor = Color.darkText.others {
didSet {
if let v: String = placeholder {
textField.attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
textField.attributedPlaceholder = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
}
}
}
......@@ -136,7 +136,7 @@ public class SearchBar : BarView {
/// Layout the clearButton.
public func layoutClearButton() {
let h: CGFloat = textField.frame.height
clearButton.frame = CGRectMake(textField.frame.width - h, 0, h, h)
clearButton.frame = CGRect(x: textField.frame.width - h, y: 0, width: h, height: h)
}
/// Clears the textField text.
......@@ -148,9 +148,9 @@ public class SearchBar : BarView {
private func prepareTextField() {
textField = UITextField()
textField.contentScaleFactor = Device.scale
textField.font = RobotoFont.regularWithSize(17)
textField.font = RobotoFont.regularWithSize(size: 17)
textField.backgroundColor = Color.clear
textField.clearButtonMode = .WhileEditing
textField.clearButtonMode = .whileEditing
tintColor = placeholderColor
textColor = Color.darkText.primary
placeholder = "Search"
......@@ -163,11 +163,10 @@ public class SearchBar : BarView {
clearButton = IconButton()
clearButton.contentEdgeInsets = UIEdgeInsets.zero
clearButton.tintColor = placeholderColor
clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted)
clearButton.setImage(image, for: .highlighted)
clearButtonAutoHandleEnabled = true
textField.clearButtonMode = .Never
textField.rightViewMode = .WhileEditing
textField.clearButtonMode = .never
textField.rightViewMode = .whileEditing
textField.rightView = clearButton
}
}
......@@ -42,7 +42,7 @@ public extension UIViewController {
if viewController is SearchBarController {
return viewController as? SearchBarController
}
viewController = viewController?.parentViewController
viewController = viewController?.parent
}
return nil
}
......
......@@ -42,7 +42,7 @@ public extension UIViewController {
if viewController is StatusBarController {
return viewController as? StatusBarController
}
viewController = viewController?.parentViewController
viewController = viewController?.parent
}
return nil
}
......@@ -80,7 +80,7 @@ public class StatusBarController : RootController {
private func prepareStatusBarView() {
statusBarView = View()
statusBarView.zPosition = 3000
statusBarView.backgroundColor = Color.black.colorWithAlphaComponent(0.12)
statusBarView.backgroundColor = Color.black.withAlphaComponent(0.12)
view.layout(statusBarView).top(0).horizontally().height(20)
}
}
......@@ -31,8 +31,8 @@
import UIKit
public enum TabBarLineAlignment {
case Top
case Bottom
case top
case bottom
}
public class TabBar : View {
......@@ -40,7 +40,7 @@ public class TabBar : View {
public private(set) var line: UIView!
/// A value for the line alignment.
public var lineAlignment: TabBarLineAlignment = .Bottom {
public var lineAlignment: TabBarLineAlignment = .bottom {
didSet {
layoutSubviews()
}
......@@ -79,20 +79,21 @@ public class TabBar : View {
b.grid.columns = columns
b.contentEdgeInsets = UIEdgeInsets.zero
b.layer.cornerRadius = 0
b.removeTarget(self, action: #selector(handleButton(_:)), forControlEvents: .TouchUpInside)
b.addTarget(self, action: #selector(handleButton(_:)), forControlEvents: .TouchUpInside)
b.removeTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
b.addTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
}
grid.views = v as [UIView]
line.frame = CGRectMake(0, .Bottom == lineAlignment ? height - 3 : 0, v.first!.frame.width, 3)
line.frame = CGRect(x: 0, y: .bottom == lineAlignment ? height - 3 : 0, width: v.first!.frame.width, height: 3)
}
}
}
}
/// Handles the button touch event.
@objc
internal func handleButton(button: UIButton) {
UIView.animateWithDuration(0.25, animations: { [weak self] in
if let s: TabBar = self {
UIView.animate(withDuration: 0.25, animations: { [weak self] in
if let s = self {
s.line.frame.origin.x = button.frame.origin.x
s.line.frame.size.width = button.frame.size.width
}
......@@ -108,7 +109,7 @@ public class TabBar : View {
*/
public override func prepareView() {
super.prepareView()
autoresizingMask = .FlexibleWidth
autoresizingMask = .flexibleWidth
contentScaleFactor = Device.scale
prepareBottomLayer()
}
......
......@@ -44,6 +44,7 @@ public protocol TextDelegate {
- Parameter range: The range of characters that are being
edited.
*/
@objc
optional func textWillProcessEdit(text: Text, textStorage: TextStorage, string: String, range: NSRange)
/**
......@@ -60,7 +61,8 @@ public protocol TextDelegate {
- Parameter stop: Halts a service which is either
publishing or resolving.
*/
optional func textDidProcessEdit(text: Text, textStorage: TextStorage, string: String, result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>)
@objc
optional func textDidProcessEdit(text: Text, textStorage: TextStorage, string: String, result: TextCheckingResult?, flags: RegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>)
}
@objc(Text)
......@@ -111,19 +113,19 @@ public class Text : NSObject {
/// Prepares the TextStorage regular expression for matching.
private func prepareTextStorageExpression() {
textStorage.expression = try? NSRegularExpression(pattern: pattern, options: [])
textStorage.expression = try? RegularExpression(pattern: pattern, options: [])
}
/// Prepares the pre and post processing callbacks.
private func prepareTextStorageProcessingCallbacks() {
textStorage.textWillProcessEdit = { [weak self] (textStorage: TextStorage, string: String, range: NSRange) -> Void in
if let s: Text = self {
s.delegate?.textWillProcessEdit?(s, textStorage: textStorage, string: string, range: range)
s.delegate?.textWillProcessEdit?(text: s, textStorage: textStorage, string: string, range: range)
}
}
textStorage.textDidProcessEdit = { [weak self] (textStorage: TextStorage, result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
textStorage.textDidProcessEdit = { [weak self] (textStorage: TextStorage, result: TextCheckingResult?, flags: RegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
if let s: Text = self {
s.delegate?.textDidProcessEdit?(s, textStorage: textStorage, string: textStorage.string, result: result, flags: flags, stop: stop)
s.delegate?.textDidProcessEdit?(text: s, textStorage: textStorage, string: textStorage.string, result: result, flags: flags, stop: stop)
}
}
}
......
......@@ -30,10 +30,10 @@
import UIKit
public protocol TextFieldDelegate : UITextFieldDelegate {}
public protocol TextFieldDelegate: UITextFieldDelegate {}
@IBDesignable
public class TextField : UITextField {
public class TextField: UITextField {
/// A Boolean that indicates if the TextField is in an animating state.
public private(set) var animating: Bool = false
......@@ -96,7 +96,7 @@ public class TextField : UITextField {
/// Sets the divider.
@IBInspectable public var dividerColor: UIColor = Color.darkText.dividers {
didSet {
if !editing {
if !isEditing {
divider.backgroundColor = dividerColor.cgColor
}
}
......@@ -106,7 +106,7 @@ public class TextField : UITextField {
@IBInspectable public var dividerActiveColor: UIColor? {
didSet {
if let v: UIColor = dividerActiveColor {
if editing {
if isEditing {
divider.backgroundColor = v.cgColor
}
}
......@@ -137,7 +137,7 @@ public class TextField : UITextField {
set(value) {
placeholderLabel.text = value
if let v: String = value {
placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
placeholderLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
}
}
}
......@@ -148,9 +148,9 @@ public class TextField : UITextField {
/// Placeholder textColor.
@IBInspectable public var placeholderColor: UIColor = Color.darkText.others {
didSet {
if !editing {
if !isEditing {
if let v: String = placeholder {
placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
placeholderLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
}
}
}
......@@ -159,9 +159,9 @@ public class TextField : UITextField {
/// Placeholder active textColor.
@IBInspectable public var placeholderActiveColor: UIColor = Color.blue.base {
didSet {
if editing {
if isEditing {
if let v: String = placeholder {
placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderActiveColor])
placeholderLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderActiveColor])
}
}
tintColor = placeholderActiveColor
......@@ -183,7 +183,7 @@ public class TextField : UITextField {
set(value) {
detailLabel.text = value
if let v: String = value {
detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
detailLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
}
layoutDetailLabel()
}
......@@ -193,7 +193,7 @@ public class TextField : UITextField {
@IBInspectable public var detailColor: UIColor = Color.darkText.others {
didSet {
if let v: String = detailLabel.text {
detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
detailLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
}
}
}
......@@ -228,17 +228,16 @@ public class TextField : UITextField {
let image: UIImage? = Icon.cm.clear
clearIconButton = IconButton(frame: CGRect.zero)
clearIconButton!.contentEdgeInsets = UIEdgeInsets.zero
clearIconButton!.pulseAnimation = .Center
clearIconButton!.pulseAnimation = .center
clearIconButton!.tintColor = placeholderColor
clearIconButton!.setImage(image, forState: .Normal)
clearIconButton!.setImage(image, forState: .Highlighted)
clearButtonMode = .Never
rightViewMode = .WhileEditing
clearIconButton!.setImage(image, for: .highlighted)
clearButtonMode = .never
rightViewMode = .whileEditing
rightView = clearIconButton
clearIconButtonAutoHandle = clearIconButtonAutoHandle ? true : false
}
} else {
clearIconButton?.removeTarget(self, action: #selector(handleClearIconButton), forControlEvents: .TouchUpInside)
clearIconButton?.removeTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside)
clearIconButton = nil
}
}
......@@ -247,9 +246,9 @@ public class TextField : UITextField {
/// Enables the automatic handling of the clearIconButton.
@IBInspectable public var clearIconButtonAutoHandle: Bool = true {
didSet {
clearIconButton?.removeTarget(self, action: #selector(handleClearIconButton), forControlEvents: .TouchUpInside)
clearIconButton?.removeTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside)
if clearIconButtonAutoHandle {
clearIconButton?.addTarget(self, action: #selector(handleClearIconButton), forControlEvents: .TouchUpInside)
clearIconButton?.addTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside)
}
}
}
......@@ -265,19 +264,18 @@ public class TextField : UITextField {
let image: UIImage? = Icon.visibility
visibilityIconButton = IconButton(frame: CGRect.zero)
visibilityIconButton!.contentEdgeInsets = UIEdgeInsets.zero
visibilityIconButton!.pulseAnimation = .Center
visibilityIconButton!.pulseAnimation = .center
visibilityIconButton!.tintColor = placeholderColor
visibilityIconButton!.setImage(image, forState: .Normal)
visibilityIconButton!.setImage(image, forState: .Highlighted)
visibilityIconButton!.tintColor = placeholderColor.colorWithAlphaComponent(secureTextEntry ? 0.38 : 0.54)
secureTextEntry = true
clearButtonMode = .Never
rightViewMode = .WhileEditing
visibilityIconButton!.setImage(image, for: .highlighted)
visibilityIconButton!.tintColor = placeholderColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54)
isSecureTextEntry = true
clearButtonMode = .never
rightViewMode = .whileEditing
rightView = visibilityIconButton
visibilityIconButtonAutoHandle = visibilityIconButtonAutoHandle ? true : false
}
} else {
visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), forControlEvents: .TouchUpInside)
visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside)
visibilityIconButton = nil
}
}
......@@ -286,9 +284,9 @@ public class TextField : UITextField {
/// Enables the automatic handling of the visibilityIconButton.
@IBInspectable public var visibilityIconButtonAutoHandle: Bool = true {
didSet {
visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), forControlEvents: .TouchUpInside)
visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside)
if visibilityIconButtonAutoHandle {
visibilityIconButton?.addTarget(self, action: #selector(handleVisibilityIconButton), forControlEvents: .TouchUpInside)
visibilityIconButton?.addTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside)
}
}
}
......@@ -329,8 +327,8 @@ public class TextField : UITextField {
layoutToSize()
}
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
public override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
if self.layer == layer {
layoutDivider()
}
......@@ -338,7 +336,7 @@ public class TextField : UITextField {
/// Default size when using AutoLayout.
public override func intrinsicContentSize() -> CGSize {
return CGSizeMake(width, 32)
return CGSize(width: width, height: 32)
}
/// Handles the text editing did begin state.
......@@ -363,12 +361,12 @@ public class TextField : UITextField {
/// Handles the visibilityIconButton TouchUpInside event.
public func handleVisibilityIconButton() {
secureTextEntry = !secureTextEntry
if !secureTextEntry {
isSecureTextEntry = !isSecureTextEntry
if !isSecureTextEntry {
super.font = nil
font = placeholderLabel.font
}
visibilityIconButton?.tintColor = visibilityIconButton?.tintColor.colorWithAlphaComponent(secureTextEntry ? 0.38 : 0.54)
visibilityIconButton?.tintColor = visibilityIconButton?.tintColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54)
}
/**
......@@ -380,11 +378,11 @@ public class TextField : UITextField {
*/
public func prepareView() {
super.placeholder = nil
masksToBounds = false
clipsToBounds = false
borderStyle = .none
backgroundColor = nil
textColor = Color.darkText.primary
font = RobotoFont.regularWithSize(16)
font = RobotoFont.regularWithSize(size: 16)
contentScaleFactor = Device.scale
prepareDivider()
preparePlaceholderLabel()
......@@ -405,20 +403,20 @@ public class TextField : UITextField {
/// Layout the divider.
public func layoutDivider() {
divider.frame = CGRectMake(0, height, width, editing ? dividerActiveHeight : dividerHeight)
divider.frame = CGRect(x: 0, y: height, width: width, height: isEditing ? dividerActiveHeight : dividerHeight)
}
/// Layout the placeholderLabel.
public func layoutPlaceholderLabel() {
if !editing && true == text?.isEmpty {
if !isEditing && true == text?.isEmpty {
placeholderLabel.frame = bounds
} else if CGAffineTransformIsIdentity(placeholderLabel.transform) {
} else if placeholderLabel.transform.isIdentity {
placeholderLabel.frame = bounds
placeholderLabel.transform = CGAffineTransformMakeScale(0.75, 0.75)
placeholderLabel.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
switch textAlignment {
case .Left, .Natural:
case .left, .natural:
placeholderLabel.frame.origin.x = 0
case .Right:
case .right:
placeholderLabel.frame.origin.x = width - placeholderLabel.frame.width
default:break
}
......@@ -426,11 +424,11 @@ public class TextField : UITextField {
placeholderLabel.textColor = placeholderColor
} else {
switch textAlignment {
case .Left, .Natural:
case .left, .natural:
placeholderLabel.frame.origin.x = 0
case .Right:
case .right:
placeholderLabel.frame.origin.x = width - placeholderLabel.frame.width
case .Center:
case .center:
placeholderLabel.center.x = width / 2
default:break
}
......@@ -440,24 +438,24 @@ public class TextField : UITextField {
/// Layout the detailLabel.
public func layoutDetailLabel() {
let h: CGFloat = nil == detail ? 12 : detailLabel.font.stringSize(detail!, constrainedToWidth: Double(width)).height
detailLabel.frame = CGRectMake(0, divider.frame.origin.y + detailVerticalOffset, width, h)
let h: CGFloat = nil == detail ? 12 : detailLabel.font.stringSize(string: detail!, constrainedToWidth: Double(width)).height
detailLabel.frame = CGRect(x: 0, y: divider.frame.origin.y + detailVerticalOffset, width: width, height: h)
}
/// Layout the clearIconButton.
public func layoutClearIconButton() {
if let v: IconButton = clearIconButton {
if let v = clearIconButton {
if 0 < width && 0 < height {
v.frame = CGRectMake(width - height, 0, height, height)
v.frame = CGRect(x: width - height, y: 0, width: height, height: height)
}
}
}
/// Layout the visibilityIconButton.
public func layoutVisibilityIconButton() {
if let v: IconButton = visibilityIconButton {
if let v = visibilityIconButton {
if 0 < width && 0 < height {
v.frame = CGRectMake(width - height, 0, height, height)
v.frame = CGRect(x: width - height, y: 0, width: height, height: height)
}
}
}
......@@ -476,44 +474,44 @@ public class TextField : UITextField {
/// The animation for the placeholder when editing begins.
public func placeholderEditingDidBeginAnimation() {
if CGAffineTransformIsIdentity(placeholderLabel.transform) {
if placeholderLabel.transform.isIdentity {
animating = true
UIView.animateWithDuration(0.15, animations: { [weak self] in
if let v: TextField = self {
v.placeholderLabel.transform = CGAffineTransformMakeScale(0.75, 0.75)
switch v.textAlignment {
case .Left, .Natural:
v.placeholderLabel.frame.origin.x = 0
case .Right:
v.placeholderLabel.frame.origin.x = v.width - v.placeholderLabel.frame.width
UIView.animate(withDuration: 0.15, animations: { [weak self] in
if let s = self {
s.placeholderLabel.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
switch s.textAlignment {
case .left, .natural:
s.placeholderLabel.frame.origin.x = 0
case .right:
s.placeholderLabel.frame.origin.x = s.width - s.placeholderLabel.frame.width
default:break
}
v.placeholderLabel.frame.origin.y = -v.placeholderLabel.frame.size.height + v.placeholderVerticalOffset
v.placeholderLabel.textColor = v.placeholderActiveColor
s.placeholderLabel.frame.origin.y = -s.placeholderLabel.frame.size.height + s.placeholderVerticalOffset
s.placeholderLabel.textColor = s.placeholderActiveColor
}
}) { [weak self] _ in
self?.animating = false
}
} else if editing {
} else if isEditing {
placeholderLabel.textColor = placeholderActiveColor
}
}
/// The animation for the placeholder when editing ends.
public func placeholderEditingDidEndAnimation() {
if !CGAffineTransformIsIdentity(placeholderLabel.transform) && true == text?.isEmpty {
if !placeholderLabel.transform.isIdentity && true == text?.isEmpty {
animating = true
UIView.animateWithDuration(0.15, animations: { [weak self] in
if let v: TextField = self {
v.placeholderLabel.transform = CGAffineTransformIdentity
v.placeholderLabel.frame.origin.x = 0
v.placeholderLabel.frame.origin.y = 0
v.placeholderLabel.textColor = v.placeholderColor
UIView.animate(withDuration: 0.15, animations: { [weak self] in
if let s = self {
s.placeholderLabel.transform = CGAffineTransform.identity
s.placeholderLabel.frame.origin.x = 0
s.placeholderLabel.frame.origin.y = 0
s.placeholderLabel.textColor = s.placeholderColor
}
}) { [weak self] _ in
self?.animating = false
}
} else if !editing {
} else if !isEditing {
placeholderLabel.textColor = placeholderColor
}
}
......@@ -532,19 +530,19 @@ public class TextField : UITextField {
/// Prepares the detailLabel.
private func prepareDetailLabel() {
detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.font = RobotoFont.regularWithSize(size: 12)
detailColor = Color.darkText.others
addSubview(detailLabel)
}
/// Prepares the target handlers.
private func prepareTargetHandlers() {
addTarget(self, action: #selector(handleEditingDidBegin), forControlEvents: .EditingDidBegin)
addTarget(self, action: #selector(handleEditingDidEnd), forControlEvents: .EditingDidEnd)
addTarget(self, action: #selector(handleEditingDidBegin), for: .editingDidBegin)
addTarget(self, action: #selector(handleEditingDidEnd), for: .editingDidEnd)
}
/// Prepares the textAlignment.
private func prepareTextAlignment() {
textAlignment = .RightToLeft == UIApplication.sharedApplication().userInterfaceLayoutDirection ? .Right : .Left
textAlignment = .rightToLeft == UIApplication.shared().userInterfaceLayoutDirection ? .right : .left
}
}
......@@ -31,7 +31,7 @@
import UIKit
internal typealias TextWillProcessEdit = (TextStorage, String, NSRange) -> Void
internal typealias TextDidProcessEdit = (TextStorage, NSTextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
internal typealias TextDidProcessEdit = (TextStorage, TextCheckingResult?, RegularExpression.MatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
public class TextStorage: NSTextStorage {
/// A callback that is executed when a process edit will happen.
......@@ -44,7 +44,7 @@ public class TextStorage: NSTextStorage {
public lazy var store: NSMutableAttributedString = NSMutableAttributedString()
/// The regular expression to match text fragments against.
public var expression: NSRegularExpression?
public var expression: RegularExpression?
/// Initializer.
public required init?(coder aDecoder: NSCoder) {
......@@ -63,11 +63,11 @@ public class TextStorage: NSTextStorage {
/// Processes the text when editing.
public override func processEditing() {
let range: NSRange = (string as NSString).paragraphRangeForRange(editedRange)
let range: NSRange = (string as NSString).paragraphRange(for: editedRange)
textWillProcessEdit?(self, string, range)
expression!.enumerateMatchesInString(string, options: [], range: range) { (result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
expression!.enumerateMatches(in: string, options: [], range: range) { (result: TextCheckingResult?, flags: RegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
self.textDidProcessEdit?(self, result, flags, stop)
}
super.processEditing()
......@@ -85,8 +85,8 @@ public class TextStorage: NSTextStorage {
If you don't need this value, pass NULL.
- Returns: The attributes for the character at index.
*/
public override func attributesAtIndex(location: Int, effectiveRange range: NSRangePointer) -> [String : AnyObject] {
return store.attributesAtIndex(location, effectiveRange: range)
public override func attributes(at location: Int, effectiveRange range: NSRangePointer?) -> [String : AnyObject] {
return store.attributes(at: location, effectiveRange: range)
}
/**
......@@ -95,9 +95,9 @@ public class TextStorage: NSTextStorage {
- Parameter str: The string value that the characters
will be replaced with.
*/
public override func replaceCharactersInRange(range: NSRange, withString str: String) {
store.replaceCharactersInRange(range, withString: str)
edited(NSTextStorageEditActions.EditedCharacters, range: range, changeInLength: str.utf16.count - range.length)
public override func replaceCharacters(in range: NSRange, with str: String) {
store.replaceCharacters(in: range, with: str)
edited(NSTextStorageEditActions.editedCharacters, range: range, changeInLength: str.utf16.count - range.length)
}
/**
......@@ -106,8 +106,8 @@ public class TextStorage: NSTextStorage {
- Parameter range: A range of characters that will have their
attributes updated.
*/
public override func setAttributes(attrs: [String : AnyObject]?, range: NSRange) {
public override func setAttributes(_ attrs: [String : AnyObject]?, range: NSRange) {
store.setAttributes(attrs, range: range)
edited(NSTextStorageEditActions.EditedAttributes, range: range, changeInLength: 0)
edited(NSTextStorageEditActions.editedAttributes, range: range, changeInLength: 0)
}
}
......@@ -134,7 +134,7 @@ public class TextView: UITextView {
}
/// An override to the attributedText property.
public override var attributedText: NSAttributedString! {
public override var attributedText: AttributedString! {
didSet {
handleTextViewTextDidChange()
}
......@@ -151,7 +151,7 @@ public class TextView: UITextView {
}
/// Text container UIEdgeInset property.
public override var textContainerInset: Insets {
public override var textContainerInset: EdgeInsets {
didSet {
reloadView()
}
......@@ -244,12 +244,12 @@ public class TextView: UITextView {
/// Sets the shadow path.
internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled {
if .none == depth {
if .none == depthPreset {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(Animation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
}
}
......@@ -265,7 +265,7 @@ public class TextView: UITextView {
contentScaleFactor = Device.scale
textContainerInset = EdgeInsets.zero
backgroundColor = Color.white
masksToBounds = false
clipsToBounds = false
removeNotificationHandlers()
prepareNotificationHandlers()
reloadView()
......@@ -305,9 +305,9 @@ public class TextView: UITextView {
v.text = s
}
let h: CGFloat = ceil(v.font.lineHeight)
v.frame = CGRectMake(0, -h, bounds.width, h)
v.frame = CGRect(x: 0, y: -h, width: bounds.width, height: h)
v.isHidden = false
UIView.animateWithDuration(0.25, animations: { [weak self] in
UIView.animate(withDuration: 0.25, animations: { [weak self] in
if let s: TextView = self {
v.alpha = 1
v.frame.origin.y = -v.frame.height - s.titleLabelAnimationDistance
......@@ -321,7 +321,7 @@ public class TextView: UITextView {
private func hideTitleLabel() {
if let v: UILabel = titleLabel {
if !v.isHidden {
UIView.animateWithDuration(0.25, animations: {
UIView.animate(withDuration: 0.25, animations: {
v.alpha = 0
v.frame.origin.y = -v.frame.height
}) { _ in
......@@ -333,15 +333,17 @@ public class TextView: UITextView {
/// Prepares the Notification handlers.
private func prepareNotificationHandlers() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidBegin), name: UITextViewTextDidBeginEditingNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidChange), name: UITextViewTextDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidEnd), name: UITextViewTextDidEndEditingNotification, object: nil)
let defaultCenter = NotificationCenter.default()
defaultCenter.addObserver(self, selector: #selector(handleTextViewTextDidBegin), name: NSNotification.Name.UITextViewTextDidBeginEditing, object: self)
defaultCenter.addObserver(self, selector: #selector(handleTextViewTextDidChange), name: NSNotification.Name.UITextViewTextDidChange, object: self)
defaultCenter.addObserver(self, selector: #selector(handleTextViewTextDidEnd), name: NSNotification.Name.UITextViewTextDidEndEditing, object: self)
}
/// Removes the Notification handlers.
private func removeNotificationHandlers() {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidBeginEditingNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidEndEditingNotification, object: nil)
let defaultCenter = NotificationCenter.default()
defaultCenter.removeObserver(self, name: NSNotification.Name.UITextViewTextDidBeginEditing, object: self)
defaultCenter.removeObserver(self, name: NSNotification.Name.UITextViewTextDidChange, object: self)
defaultCenter.removeObserver(self, name: NSNotification.Name.UITextViewTextDidEndEditing, object: self)
}
}
......@@ -144,15 +144,15 @@ public class Toolbar : BarView {
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.contentScaleFactor = Device.scale
titleLabel.font = RobotoFont.mediumWithSize(17)
titleLabel.textAlignment = .Left
titleLabel.font = RobotoFont.mediumWithSize(size: 17)
titleLabel.textAlignment = .left
}
/// Prepares the detailLabel.
private func prepareDetailLabel() {
detailLabel = UILabel()
detailLabel.contentScaleFactor = Device.scale
detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.textAlignment = .Left
detailLabel.font = RobotoFont.regularWithSize(size: 12)
detailLabel.textAlignment = .left
}
}
......@@ -42,7 +42,7 @@ public extension UIViewController {
if viewController is ToolbarController {
return viewController as? ToolbarController
}
viewController = viewController?.parentViewController
viewController = viewController?.parent
}
return nil
}
......@@ -51,15 +51,19 @@ public extension UIViewController {
@objc(ToolbarControllerDelegate)
public protocol ToolbarControllerDelegate : MaterialDelegate {
/// Delegation method that executes when the floatingViewController will open.
@objc
optional func toolbarControllerWillOpenFloatingViewController(toolbarController: ToolbarController)
/// Delegation method that executes when the floatingViewController will close.
@objc
optional func toolbarControllerWillCloseFloatingViewController(toolbarController: ToolbarController)
/// Delegation method that executes when the floatingViewController did open.
@objc
optional func toolbarControllerDidOpenFloatingViewController(toolbarController: ToolbarController)
/// Delegation method that executes when the floatingViewController did close.
@objc
optional func toolbarControllerDidCloseFloatingViewController(toolbarController: ToolbarController)
}
......@@ -83,26 +87,26 @@ public class ToolbarController : RootController {
if let v: UIViewController = internalFloatingViewController {
v.view.layer.rasterizationScale = Device.scale
v.view.layer.shouldRasterize = true
delegate?.toolbarControllerWillCloseFloatingViewController?(self)
delegate?.toolbarControllerWillCloseFloatingViewController?(toolbarController: self)
internalFloatingViewController = nil
UIView.animateWithDuration(0.5,
UIView.animate(withDuration: 0.5,
animations: { [weak self] in
if let s: ToolbarController = self {
if let s = self {
v.view.center.y = 2 * s.view.bounds.height
s.toolbar.alpha = 1
s.rootViewController.view.alpha = 1
}
}) { [weak self] _ in
if let s: ToolbarController = self {
v.willMoveToParentViewController(nil)
if let s = self {
v.willMove(toParentViewController: nil)
v.view.removeFromSuperview()
v.removeFromParentViewController()
v.view.layer.shouldRasterize = false
s.isUserInteractionEnabled = true
s.toolbar.isUserInteractionEnabled = true
dispatch_async(dispatch_get_main_queue()) { [weak self] in
if let s: ToolbarController = self {
s.delegate?.toolbarControllerDidCloseFloatingViewController?(s)
DispatchQueue.main.async { [weak self] in
if let s = self {
s.delegate?.toolbarControllerDidCloseFloatingViewController?(toolbarController: s)
}
}
}
......@@ -117,7 +121,7 @@ public class ToolbarController : RootController {
v.view.isHidden = true
view.insertSubview(v.view, aboveSubview: toolbar)
v.view.layer.zPosition = 1500
v.didMoveToParentViewController(self)
v.didMove(toParentViewController: self)
// Animate the noteButton out and the noteViewController! in.
v.view.isHidden = false
......@@ -128,21 +132,21 @@ public class ToolbarController : RootController {
internalFloatingViewController = v
isUserInteractionEnabled = false
toolbar.isUserInteractionEnabled = false
delegate?.toolbarControllerWillOpenFloatingViewController?(self)
UIView.animateWithDuration(0.5,
delegate?.toolbarControllerWillOpenFloatingViewController?(toolbarController: self)
UIView.animate(withDuration: 0.5,
animations: { [weak self] in
if let s: ToolbarController = self {
if let s = self {
v.view.center.y = s.view.bounds.height / 2
s.toolbar.alpha = 0.5
s.rootViewController.view.alpha = 0.5
}
}) { [weak self] _ in
if let s: ToolbarController = self {
if let s = self {
v.view.layer.shouldRasterize = false
s.view.layer.shouldRasterize = false
dispatch_async(dispatch_get_main_queue()) { [weak self] in
if let s: ToolbarController = self {
s.delegate?.toolbarControllerDidOpenFloatingViewController?(s)
DispatchQueue.main.async { [weak self] in
if let s = self {
s.delegate?.toolbarControllerDidOpenFloatingViewController?(toolbarController: s)
}
}
}
......
......@@ -186,20 +186,6 @@ public class View: UIView {
}
}
/// A property that accesses the layer.cornerRadius.
@IBInspectable public var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set(value) {
layer.cornerRadius = value
layoutShadowPath()
if .circle == shape {
shape = .none
}
}
}
/**
A property that manages the overall shape for the object. If either the
width or height property is set, the other will be automatically adjusted
......
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