Commit 9a90a7d5 by Daniel Dahan

cleanup and removal of duplicate code

parent e15b9fff
...@@ -69,7 +69,7 @@ public struct Animation { ...@@ -69,7 +69,7 @@ public struct Animation {
let delayed: AnimationDelayCancelBlock = { (cancel: Bool) in let delayed: AnimationDelayCancelBlock = { (cancel: Bool) in
if !cancel { if !cancel {
DispatchQueue.main.asynchronously(execute: completion) DispatchQueue.main.async(execute: completion)
} }
cancelable = nil cancelable = nil
} }
......
...@@ -67,6 +67,6 @@ public class BarView : ControlView { ...@@ -67,6 +67,6 @@ public class BarView : ControlView {
*/ */
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
depth = .depth1 depthPreset = .depth1
} }
} }
...@@ -31,15 +31,15 @@ ...@@ -31,15 +31,15 @@
import UIKit import UIKit
public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControllerAnimatedTransitioning { public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControllerAnimatedTransitioning {
public func animateTransition(transitionContext: UIViewControllerContextTransitioning) { public func animateTransition(_ transitionContext: UIViewControllerContextTransitioning) {
let fromView : UIView = transitionContext.viewForKey(UITransitionContextFromViewKey)! let fromView : UIView = transitionContext.view(forKey: UITransitionContextFromViewKey)!
let toView : UIView = transitionContext.viewForKey(UITransitionContextToViewKey)! let toView : UIView = transitionContext.view(forKey: UITransitionContextToViewKey)!
toView.alpha = 0 toView.alpha = 0
transitionContext.containerView()!.addSubview(fromView) transitionContext.containerView().addSubview(fromView)
transitionContext.containerView()!.addSubview(toView) transitionContext.containerView().addSubview(toView)
UIView.animateWithDuration(transitionDuration(transitionContext), UIView.animate(withDuration: transitionDuration(transitionContext),
animations: { _ in animations: { _ in
toView.alpha = 1 toView.alpha = 1
fromView.alpha = 0 fromView.alpha = 0
...@@ -48,20 +48,20 @@ public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControl ...@@ -48,20 +48,20 @@ public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControl
} }
} }
public func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { public func transitionDuration(_ transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.35 return 0.35
} }
} }
public enum BottomNavigationTransitionAnimation { public enum BottomNavigationTransitionAnimation {
case None case none
case Fade case fade
} }
@IBDesignable @IBDesignable
public class BottomNavigationController : UITabBarController, UITabBarControllerDelegate { public class BottomNavigationController : UITabBarController, UITabBarControllerDelegate {
/// The transition animation to use when selecting a new tab. /// 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. An initializer that initializes the object with a NSCoder object.
...@@ -76,7 +76,7 @@ public class BottomNavigationController : UITabBarController, UITabBarController ...@@ -76,7 +76,7 @@ public class BottomNavigationController : UITabBarController, UITabBarController
- Parameter nibNameOrNil: An Optional String for the nib. - Parameter nibNameOrNil: An Optional String for the nib.
- Parameter bundle: An Optional NSBundle where the nib is located. - 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) super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
} }
...@@ -134,19 +134,19 @@ public class BottomNavigationController : UITabBarController, UITabBarController ...@@ -134,19 +134,19 @@ public class BottomNavigationController : UITabBarController, UITabBarController
} }
/// Handles transitions when tabBarItems are pressed. /// 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 fVC: UIViewController? = fromVC
let tVC: UIViewController? = toVC let tVC: UIViewController? = toVC
if nil == fVC || nil == tVC { if nil == fVC || nil == tVC {
return nil return nil
} }
return .Fade == transitionAnimation ? BottomNavigationFadeAnimatedTransitioning() : nil return .fade == transitionAnimation ? BottomNavigationFadeAnimatedTransitioning() : nil
} }
/// Prepares the tabBar. /// Prepares the tabBar.
private func prepareTabBar() { private func prepareTabBar() {
tabBar.depth = .depth1 tabBar.depthPreset = .depth1
let image: UIImage? = UIImage.imageWithColor(Color.clear, size: CGSizeMake(1, 1)) let image = UIImage.imageWithColor(color: Color.clear, size: CGSize(width: 1, height: 1))
tabBar.shadowImage = image tabBar.shadowImage = image
tabBar.backgroundImage = image tabBar.backgroundImage = image
tabBar.backgroundColor = Color.white tabBar.backgroundColor = Color.white
......
...@@ -114,6 +114,11 @@ public class BottomTabBar: UITabBar { ...@@ -114,6 +114,11 @@ public class BottomTabBar: UITabBar {
public convenience init() { public convenience init() {
self.init(frame: CGRect.zero) self.init(frame: CGRect.zero)
} }
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
}
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
......
...@@ -164,7 +164,7 @@ public class Button: UIButton { ...@@ -164,7 +164,7 @@ public class Button: UIButton {
*/ */
@IBInspectable public var contentInset = EdgeInsets.zero { @IBInspectable public var contentInset = EdgeInsets.zero {
didSet { didSet {
contentEdgeInsets = contentInset.asEdgeInsets contentEdgeInsets = contentInset
} }
} }
......
...@@ -47,7 +47,7 @@ public class ControlView : View { ...@@ -47,7 +47,7 @@ public class ControlView : View {
} }
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
@IBInspectable public var contentInset: Inset { @IBInspectable public var contentInset: EdgeInsets {
get { get {
return grid.contentInset return grid.contentInset
} }
...@@ -152,7 +152,7 @@ public class ControlView : View { ...@@ -152,7 +152,7 @@ public class ControlView : View {
public init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) { public init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
super.init(frame: CGRect.zero) super.init(frame: CGRect.zero)
frame.size = intrinsicContentSize() frame.size = intrinsicContentSize()
prepareProperties(leftControls, rightControls: rightControls) prepareProperties(leftControls: leftControls, rightControls: rightControls)
} }
public override func layoutSubviews() { public override func layoutSubviews() {
...@@ -214,7 +214,7 @@ public class ControlView : View { ...@@ -214,7 +214,7 @@ public class ControlView : View {
} }
public override func intrinsicContentSize() -> CGSize { public override func intrinsicContentSize() -> CGSize {
return CGSizeMake(width, 44) return CGSize(width: width, height: 44)
} }
/** /**
...@@ -227,8 +227,8 @@ public class ControlView : View { ...@@ -227,8 +227,8 @@ public class ControlView : View {
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
interimSpacePreset = .interimSpace1 interimSpacePreset = .interimSpace1
contentEdgeInsetsPreset = .Square1 contentEdgeInsetsPreset = .square1
autoresizingMask = .FlexibleWidth autoresizingMask = .flexibleWidth
shadowPathAutoSizeEnabled = false shadowPathAutoSizeEnabled = false
prepareContentView() prepareContentView()
} }
......
...@@ -50,7 +50,7 @@ public struct Depth { ...@@ -50,7 +50,7 @@ public struct Depth {
public var radius: CGFloat public var radius: CGFloat
/// Preset. /// Preset.
public var preset: DepthPreset { public var preset: DepthPreset = .none {
didSet { didSet {
let depth = DepthPresetToValue(preset: preset) let depth = DepthPresetToValue(preset: preset)
offset = depth.offset offset = depth.offset
...@@ -76,6 +76,7 @@ public struct Depth { ...@@ -76,6 +76,7 @@ public struct Depth {
- Parameter preset: DepthPreset. - Parameter preset: DepthPreset.
*/ */
public init(preset: DepthPreset) { public init(preset: DepthPreset) {
self.init()
self.preset = preset self.preset = preset
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
import UIKit import UIKit
public class ErrorTextField : TextField { public class ErrorTextField: TextField {
/// Controls the visibility of detailLabel /// Controls the visibility of detailLabel
@IBInspectable public var revealError: Bool = false { @IBInspectable public var revealError: Bool = false {
didSet { didSet {
......
...@@ -150,7 +150,7 @@ public class Grid { ...@@ -150,7 +150,7 @@ public class Grid {
} }
/// Insets value for grid. /// Insets value for grid.
public var contentInset: Inset = EdgeInsetsPresetToValue(preset: .none) { public var contentInset: EdgeInsets = EdgeInsetsPresetToValue(preset: .none) {
didSet { didSet {
reload() reload()
} }
......
...@@ -32,26 +32,29 @@ import UIKit ...@@ -32,26 +32,29 @@ import UIKit
public struct Icon { public struct Icon {
/// An internal reference to the icons bundle. /// 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 A public reference to the icons bundle, that aims to detect
the correct bundle to use. the correct bundle to use.
*/ */
public static var bundle: NSBundle { public static var bundle: Bundle {
if nil == Icon.internalBundle { if nil == Icon.internalBundle {
Icon.internalBundle = NSBundle(forClass: View.self) Icon.internalBundle = Bundle(for: View.self)
let b: NSBundle? = NSBundle(URL: Icon.internalBundle!.resourceURL!.URLByAppendingPathComponent("io.cosmicmind.material.icons.bundle")) let url = Icon.internalBundle!.resourceURL!
if let v: NSBundle = b { do {
Icon.internalBundle = v let b = Bundle(url: try url.appendingPathComponent("io.cosmicmind.material.icons.bundle"))
} if let v = b {
Icon.internalBundle = v
}
} catch {}
} }
return Icon.internalBundle! return Icon.internalBundle!
} }
/// Get the icon by the file name. /// Get the icon by the file name.
public static func icon(name: String) -> UIImage? { public static func icon(_ name: String) -> UIImage? {
return UIImage(named: name, inBundle: bundle, compatibleWithTraitCollection: nil)?.imageWithRenderingMode(.AlwaysTemplate) return UIImage(named: name, in: bundle, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate)
} }
/// Google icons. /// Google icons.
......
...@@ -285,62 +285,53 @@ public class Layer: CAShapeLayer { ...@@ -285,62 +285,53 @@ public class Layer: CAShapeLayer {
layoutShadowPath() layoutShadowPath()
} }
/** /**
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. - Parameter animation: A CAAnimation instance.
*/ */
public func animate(animation: CAAnimation) { public func animate(animation: CAAnimation) {
animation.delegate = self 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!) 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!) add(a, forKey: a.keyPath!)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup { } else if let a = animation as? CAAnimationGroup {
add(a, forKey: nil) add(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition { } else if let a = animation as? CATransition {
add(a, forKey: kCATransition) 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. 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 - Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false because it was completed or interrupted. True if completed, false
if interrupted. if interrupted.
*/ */
public override func animationDidStop(_ animation: CAAnimation, finished flag: Bool) { public override func animationDidStop(_ animation: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation { if let a = animation as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b = a as? CABasicAnimation {
if let v: AnyObject = b.toValue { if let v = b.toValue {
if let k: String = b.keyPath { if let k = b.keyPath {
setValue(v, forKeyPath: k) setValue(v, forKeyPath: k)
removeAnimation(forKey: k) removeAnimation(forKey: k)
} }
} }
} }
(delegate as? AnimationDelegate)?.materialAnimationDidStop?(animation: animation, finished: flag) } else if let a = animation as? CAAnimationGroup {
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup { for x in a.animations! {
for x in a.animations! { animationDidStop(x, finished: true)
animationDidStop(x, finished: true) }
} }
} }
}
/// Prepares the visualLayer property. /// Prepares the visualLayer property.
public func prepareVisualLayer() { public func prepareVisualLayer() {
visualLayer = CAShapeLayer(Z visualLayer = CAShapeLayer()
visualLayer.zPosition = 0 visualLayer.zPosition = 0
visualLayer.masksToBounds = true visualLayer.masksToBounds = true
addSublayer(visualLayer) addSublayer(visualLayer)
......
/* ///*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. //* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved. //* All rights reserved.
* //*
* Redistribution and use in source and binary forms, with or without //* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: //* modification, are permitted provided that the following conditions are met:
* //*
* * Redistributions of source code must retain the above copyright notice, this //* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. //* list of conditions and the following disclaimer.
* //*
* * Redistributions in binary form must reproduce the above copyright notice, //* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation //* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. //* and/or other materials provided with the distribution.
* //*
* * Neither the name of CosmicMind nor the names of its //* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from //* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. //* this software without specific prior written permission.
* //*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" //* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE //* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE //* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE //* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL //* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR //* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER //* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, //* 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 //* 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. //* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ //*/
//
import UIKit //import UIKit
//
public extension String { //public extension String {
/** // /**
:name: lines // :name: lines
*/ // */
public var lines: Array<String> { // public var lines: Array<String> {
return componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet()) // return componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet())
} // }
//
/** // /**
:name: firstLine // :name: firstLine
*/ // */
public var firstLine: String? { // public var firstLine: String? {
return lines.first?.trim() // return lines.first?.trim()
} // }
//
/** // /**
:name: lastLine // :name: lastLine
*/ // */
public var lastLine: String? { // public var lastLine: String? {
return lines.last?.trim() // return lines.last?.trim()
} // }
//
/** // /**
:name: replaceNewLineCharater // :name: replaceNewLineCharater
*/ // */
public func replaceNewLineCharater(replace: String = " ") -> String { // public func replaceNewLineCharater(replace: String = " ") -> String {
return componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).joinWithSeparator(replace).trim() // return componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).joinWithSeparator(replace).trim()
} // }
//
/** // /**
:name: replacePunctuationCharacters // :name: replacePunctuationCharacters
*/ // */
public func replacePunctuationCharacters(replace: String = "") -> String { // public func replacePunctuationCharacters(replace: String = "") -> String {
return componentsSeparatedByCharactersInSet(NSCharacterSet.punctuationCharacterSet()).joinWithSeparator(replace).trim() // return componentsSeparatedByCharactersInSet(NSCharacterSet.punctuationCharacterSet()).joinWithSeparator(replace).trim()
} // }
//
/** // /**
:name: trim // :name: trim
*/ // */
public func trim() -> String { // public func trim() -> String {
return stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) // return stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
} // }
} //}
...@@ -35,8 +35,8 @@ public extension UIFont { ...@@ -35,8 +35,8 @@ public extension UIFont {
:name: stringSize :name: stringSize
*/ */
public func stringSize(string: String, constrainedToWidth width: Double) -> CGSize { public func stringSize(string: String, constrainedToWidth width: Double) -> CGSize {
return string.boundingRectWithSize(CGSize(width: width, height: DBL_MAX), return string.boundingRect(with: CGSize(width: width, height: DBL_MAX),
options: NSStringDrawingOptions.UsesLineFragmentOrigin, options: NSStringDrawingOptions.usesLineFragmentOrigin,
attributes: [NSFontAttributeName: self], attributes: [NSFontAttributeName: self],
context: nil).size 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
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 { ...@@ -45,9 +45,9 @@ public extension UIImage {
} }
let g: 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) UIGraphicsBeginImageContextWithOptions(t.size, false, Device.scale)
drawInRect(t, blendMode: .Normal, alpha: 1) draw(in: t, blendMode: .normal, alpha: 1)
g = UIGraphicsGetImageFromCurrentImageContext() g = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext() 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 @@ ...@@ -30,7 +30,151 @@
import UIKit import UIKit
public enum ImageFormatType { public enum ImageFormat {
case PNG case png
case JPEG case jpeg
} }
\ No newline at end of file
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 { ...@@ -43,7 +43,7 @@ public class Material {
} }
/// A property that sets the cornerRadius of the backing layer. /// A property that sets the cornerRadius of the backing layer.
public var cornerRadiusPreset: CornerRadiusPreset { public var cornerRadiusPreset: CornerRadiusPreset = .none {
didSet { didSet {
guard let v = view else { guard let v = view else {
return return
...@@ -56,7 +56,7 @@ public class Material { ...@@ -56,7 +56,7 @@ public class Material {
} }
/// A preset property to set the borderWidth. /// A preset property to set the borderWidth.
public var borderWidthPreset: BorderWidthPreset { public var borderWidthPreset: BorderWidthPreset = .none {
didSet { didSet {
guard let v = view else { guard let v = view else {
return return
...@@ -79,7 +79,7 @@ public class Material { ...@@ -79,7 +79,7 @@ public class Material {
} }
/// Grid reference. /// Grid reference.
public var depth: Depth { public var depth: Depth = Depth.zero {
didSet { didSet {
guard let v = view else { guard let v = view else {
return return
...@@ -98,7 +98,7 @@ private var MaterialKey: UInt8 = 0 ...@@ -98,7 +98,7 @@ private var MaterialKey: UInt8 = 0
/// Grid extension for UIView. /// Grid extension for UIView.
public extension UIView { public extension UIView {
/// Material Reference. /// Material Reference.
private var material: Material { internal var material: Material {
get { get {
return AssociatedObject(base: self, key: &MaterialKey) { return AssociatedObject(base: self, key: &MaterialKey) {
return Material(view: self) return Material(view: self)
......
...@@ -264,8 +264,6 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -264,8 +264,6 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
depthPreset = .none
cornerRadiusPreset = .none
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView() prepareView()
...@@ -278,8 +276,6 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -278,8 +276,6 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
depthPreset = .none
cornerRadiusPreset = .none
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
......
...@@ -264,7 +264,6 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -264,7 +264,6 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
cornerRadiusPreset = .none
shape = .none shape = .none
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
...@@ -278,7 +277,6 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -278,7 +277,6 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
cornerRadiusPreset = .none
shape = .none shape = .none
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(frame: frame) super.init(frame: frame)
......
...@@ -77,53 +77,53 @@ public class MaterialCollectionViewLayout: UICollectionViewLayout { ...@@ -77,53 +77,53 @@ public class MaterialCollectionViewLayout: UICollectionViewLayout {
public func indexPathsOfItemsInRect(rect: CGRect) -> Array<NSIndexPath> { public func indexPathsOfItemsInRect(rect: CGRect) -> Array<NSIndexPath> {
var paths: Array<NSIndexPath> = Array<NSIndexPath>() var paths: Array<NSIndexPath> = Array<NSIndexPath>()
for (attribute, indexPath) in layoutItems { for (attribute, indexPath) in layoutItems {
if CGRectIntersectsRect(rect, attribute.frame) { if rect.intersects(attribute.frame) {
paths.append(indexPath) paths.append(indexPath)
} }
} }
return paths return paths
} }
public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { public override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath) let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
let item: MaterialDataSourceItem = dataSourceItems![indexPath.item] let item: MaterialDataSourceItem = dataSourceItems![indexPath.item!]
if 0 < itemSize.width && 0 < itemSize.height { 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) 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 { } 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: contentInset.left, y: offset.y, width: collectionView!.bounds.width - contentInset.left - contentInset.right, height: item.height ?? collectionView!.bounds.height)
} else { } 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 return attributes
} }
public override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { public override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var layoutAttributes: Array<UICollectionViewLayoutAttributes> = Array<UICollectionViewLayoutAttributes>() var layoutAttributes: Array<UICollectionViewLayoutAttributes> = Array<UICollectionViewLayoutAttributes>()
for (attribute, _) in layoutItems { for (attribute, _) in layoutItems {
if CGRectIntersectsRect(rect, attribute.frame) { if rect.intersects(attribute.frame) {
layoutAttributes.append(attribute) layoutAttributes.append(attribute)
} }
} }
return layoutAttributes return layoutAttributes
} }
public override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool { public override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
return .Vertical == scrollDirection ? newBounds.width != collectionView!.bounds.width : newBounds.height != collectionView!.bounds.height return .vertical == scrollDirection ? newBounds.width != collectionView!.bounds.width : newBounds.height != collectionView!.bounds.height
} }
public override func collectionViewContentSize() -> CGSize { public override func collectionViewContentSize() -> CGSize {
return contentSize return contentSize
} }
public override func prepareLayout() { public override func prepare() {
if let dataSource: MaterialCollectionViewDataSource = collectionView?.dataSource as? MaterialCollectionViewDataSource { 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 return proposedContentOffset
} }
...@@ -134,12 +134,10 @@ public class MaterialCollectionViewLayout: UICollectionViewLayout { ...@@ -134,12 +134,10 @@ public class MaterialCollectionViewLayout: UICollectionViewLayout {
offset.x = contentInset.left offset.x = contentInset.left
offset.y = contentInset.top offset.y = contentInset.top
var indexPath: NSIndexPath?
for i in 0..<dataSourceItems.count { for i in 0..<dataSourceItems.count {
let item: MaterialDataSourceItem = dataSourceItems[i] let item: MaterialDataSourceItem = dataSourceItems[i]
indexPath = NSIndexPath(forItem: i, inSection: 0) let indexPath = IndexPath(item: i, section: 0)
layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!)) layoutItems.append((layoutAttributesForItem(at: indexPath)!, indexPath))
offset.x += interimSpace offset.x += interimSpace
offset.x += nil == item.width ? itemSize.width : item.width! offset.x += nil == item.width ? itemSize.width : item.width!
...@@ -152,11 +150,11 @@ public class MaterialCollectionViewLayout: UICollectionViewLayout { ...@@ -152,11 +150,11 @@ public class MaterialCollectionViewLayout: UICollectionViewLayout {
offset.y += contentInset.bottom - interimSpace offset.y += contentInset.bottom - interimSpace
if 0 < itemSize.width && 0 < itemSize.height { if 0 < itemSize.width && 0 < itemSize.height {
contentSize = CGSizeMake(offset.x, offset.y) contentSize = CGSize(width: offset.x, height: offset.y)
} else if .Vertical == scrollDirection { } else if .vertical == scrollDirection {
contentSize = CGSizeMake(collectionView!.bounds.width, offset.y) contentSize = CGSize(width: collectionView!.bounds.width, height: offset.y)
} else { } 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 { ...@@ -87,7 +87,7 @@ public class MaterialLabel : UILabel {
*/ */
@IBInspectable public var wrapped: Bool { @IBInspectable public var wrapped: Bool {
didSet { didSet {
textLayer.wrapped = wrapped textLayer.isWrapped = wrapped
} }
} }
...@@ -148,6 +148,6 @@ public class MaterialLabel : UILabel { ...@@ -148,6 +148,6 @@ public class MaterialLabel : UILabel {
*/ */
public func prepareView() { public func prepareView() {
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
textAlignment = .Left textAlignment = .left
} }
} }
...@@ -240,12 +240,12 @@ public class MaterialTableViewCell: UITableViewCell { ...@@ -240,12 +240,12 @@ public class MaterialTableViewCell: UITableViewCell {
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .none == depth { if .none == depthPreset {
shadowPath = nil shadowPath = nil
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } 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 { ...@@ -37,7 +37,7 @@ public class MaterialTextLayer : CATextLayer {
public var fontType: UIFont? { public var fontType: UIFont? {
didSet { didSet {
if let v: UIFont = fontType { if let v: UIFont = fontType {
super.font = CGFontCreateWithFontName(v.fontName as CFStringRef)! super.font = CGFont(v.fontName as CFString)!
pointSize = v.pointSize pointSize = v.pointSize
} }
} }
...@@ -73,18 +73,18 @@ public class MaterialTextLayer : CATextLayer { ...@@ -73,18 +73,18 @@ public class MaterialTextLayer : CATextLayer {
/** /**
:name: textAlignment :name: textAlignment
*/ */
public var textAlignment: NSTextAlignment = .Left { public var textAlignment: NSTextAlignment = .left {
didSet { didSet {
switch textAlignment { switch textAlignment {
case .Left: case .left:
alignmentMode = kCAAlignmentLeft alignmentMode = kCAAlignmentLeft
case .Center: case .center:
alignmentMode = kCAAlignmentCenter alignmentMode = kCAAlignmentCenter
case .Right: case .right:
alignmentMode = kCAAlignmentRight alignmentMode = kCAAlignmentRight
case .Justified: case .justified:
alignmentMode = kCAAlignmentJustified alignmentMode = kCAAlignmentJustified
case .Natural: case .natural:
alignmentMode = kCAAlignmentNatural alignmentMode = kCAAlignmentNatural
} }
} }
...@@ -93,20 +93,20 @@ public class MaterialTextLayer : CATextLayer { ...@@ -93,20 +93,20 @@ public class MaterialTextLayer : CATextLayer {
/** /**
:name: lineBreakMode :name: lineBreakMode
*/ */
public var lineBreakMode: NSLineBreakMode = .ByWordWrapping { public var lineBreakMode: NSLineBreakMode = .byWordWrapping {
didSet { didSet {
switch lineBreakMode { switch lineBreakMode {
case .ByWordWrapping: // Wrap at word boundaries, default case .byWordWrapping: // Wrap at word boundaries, default
truncationMode = kCATruncationNone truncationMode = kCATruncationNone
case .ByCharWrapping: // Wrap at character boundaries case .byCharWrapping: // Wrap at character boundaries
truncationMode = kCATruncationNone truncationMode = kCATruncationNone
case .ByClipping: // Simply clip case .byClipping: // Simply clip
truncationMode = kCATruncationNone truncationMode = kCATruncationNone
case .ByTruncatingHead: // Truncate at head of line: "...wxyz" case .byTruncatingHead: // Truncate at head of line: "...wxyz"
truncationMode = kCATruncationStart truncationMode = kCATruncationStart
case .ByTruncatingTail: // Truncate at tail of line: "abcd..." case .byTruncatingTail: // Truncate at tail of line: "abcd..."
truncationMode = kCATruncationEnd truncationMode = kCATruncationEnd
case .ByTruncatingMiddle: // Truncate middle of line: "ab...yz" case .byTruncatingMiddle: // Truncate middle of line: "ab...yz"
truncationMode = kCATruncationMiddle truncationMode = kCATruncationMiddle
} }
} }
...@@ -196,9 +196,9 @@ public class MaterialTextLayer : CATextLayer { ...@@ -196,9 +196,9 @@ public class MaterialTextLayer : CATextLayer {
:name: stringSize :name: stringSize
*/ */
public func stringSize(constrainedToWidth width: Double) -> CGSize { public func stringSize(constrainedToWidth width: Double) -> CGSize {
if let v: UIFont = fontType { if let v = fontType {
if 0 < text?.utf16.count { if 0 < text?.utf16.count {
return v.stringSize(text!, constrainedToWidth: width) return v.stringSize(string: text!, constrainedToWidth: width)
} }
} }
return CGSize.zero return CGSize.zero
...@@ -209,9 +209,9 @@ public class MaterialTextLayer : CATextLayer { ...@@ -209,9 +209,9 @@ public class MaterialTextLayer : CATextLayer {
*/ */
internal func prepareLayer() { internal func prepareLayer() {
textColor = Color.black textColor = Color.black
textAlignment = .Left textAlignment = .left
wrapped = true isWrapped = true
contentsScale = Device.scale contentsScale = Device.scale
lineBreakMode = .ByWordWrapping lineBreakMode = .byWordWrapping
} }
} }
...@@ -42,7 +42,7 @@ public extension UIViewController { ...@@ -42,7 +42,7 @@ public extension UIViewController {
if viewController is MenuController { if viewController is MenuController {
return viewController as? MenuController return viewController as? MenuController
} }
viewController = viewController?.parentViewController viewController = viewController?.parent
} }
return nil return nil
} }
...@@ -62,7 +62,7 @@ public class MenuController : RootController { ...@@ -62,7 +62,7 @@ public class MenuController : RootController {
if true == isUserInteractionEnabled { if true == isUserInteractionEnabled {
isUserInteractionEnabled = false isUserInteractionEnabled = false
rootViewController.view.alpha = 0.5 rootViewController.view.alpha = 0.5
menuView.open(completion) menuView.open(completion: completion)
} }
} }
...@@ -74,7 +74,7 @@ public class MenuController : RootController { ...@@ -74,7 +74,7 @@ public class MenuController : RootController {
public func closeMenu(completion: (() -> Void)? = nil) { public func closeMenu(completion: (() -> Void)? = nil) {
if false == isUserInteractionEnabled { if false == isUserInteractionEnabled {
rootViewController.view.alpha = 1 rootViewController.view.alpha = 1
menuView.close({ [weak self] in menuView.close(completion: { [weak self] in
self?.isUserInteractionEnabled = true self?.isUserInteractionEnabled = true
completion?() completion?()
}) })
......
...@@ -33,6 +33,7 @@ import UIKit ...@@ -33,6 +33,7 @@ import UIKit
@objc(MenuViewDelegate) @objc(MenuViewDelegate)
public protocol MenuViewDelegate : MaterialDelegate { public protocol MenuViewDelegate : MaterialDelegate {
/// Gets called when the user taps outside menu buttons. /// Gets called when the user taps outside menu buttons.
@objc
optional func menuViewDidTapOutside(menuView: MenuView) optional func menuViewDidTapOutside(menuView: MenuView)
} }
...@@ -89,26 +90,26 @@ public class MenuView : PulseView { ...@@ -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, 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. we need to look at the subviews to see if we have a hit.
*/ */
guard !hidden else { guard !isHidden else {
return nil return nil
} }
for v in subviews { for v in subviews {
let p: CGPoint = v.convertPoint(point, fromView: self) let p = v.convert(point, from: self)
if CGRectContainsPoint(v.bounds, p) { if v.bounds.contains(p) {
return v.hitTest(p, withEvent: event) return v.hitTest(p, with: event)
} }
} }
if menu.opened { if menu.isOpened {
(delegate as? MenuViewDelegate)?.menuViewDidTapOutside?(self) (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 { ...@@ -69,7 +69,7 @@ public class NavigationBar : UINavigationBar {
} }
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
@IBInspectable public var contentInset: Insets = EdgeInsets.zero { @IBInspectable public var contentInset: EdgeInsets = EdgeInsets.zero {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
...@@ -205,25 +205,25 @@ public class NavigationBar : UINavigationBar { ...@@ -205,25 +205,25 @@ public class NavigationBar : UINavigationBar {
} }
} }
public override func sizeThatFits(size: CGSize) -> CGSize { public override func sizeThatFits(_ size: CGSize) -> CGSize {
return intrinsicContentSize() return intrinsicContentSize()
} }
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if let v: UINavigationItem = topItem { if let v = topItem {
layoutNavigationItem(v) layoutNavigationItem(item: v)
} }
if let v: UINavigationItem = backItem { if let v = backItem {
layoutNavigationItem(v) layoutNavigationItem(item: v)
} }
} }
public override func pushNavigationItem(item: UINavigationItem, animated: Bool) { public override func pushItem(_ item: UINavigationItem, animated: Bool) {
super.pushNavigationItem(item, animated: animated) super.pushItem(item, animated: animated)
layoutNavigationItem(item) layoutNavigationItem(item: item)
} }
/** /**
...@@ -232,100 +232,99 @@ public class NavigationBar : UINavigationBar { ...@@ -232,100 +232,99 @@ public class NavigationBar : UINavigationBar {
*/ */
internal func layoutNavigationItem(item: UINavigationItem) { internal func layoutNavigationItem(item: UINavigationItem) {
if willRenderView { if willRenderView {
prepareItem(item) prepareItem(item: item)
if let titleView: UIView = prepareTitleView(item) { let titleView = prepareTitleView(item: item)
if let contentView: UIView = prepareContentView(item) { let contentView = prepareContentView(item: item)
if let g: Int = Int(width / gridFactor) {
let columns: Int = g + 1 if let g: Int = Int(width / gridFactor) {
let columns: Int = g + 1
titleView.frame.origin = CGPoint.zero
titleView.frame.size = intrinsicContentSize() titleView.frame.origin = CGPoint.zero
titleView.grid.views = [] titleView.frame.size = intrinsicContentSize()
titleView.grid.axis.columns = columns titleView.grid.views = []
titleView.grid.axis.columns = columns
contentView.grid.columns = columns
contentView.grid.columns = columns
// leftControls
if let v: Array<UIControl> = item.leftControls { // leftControls
for c in v { if let v: Array<UIControl> = item.leftControls {
let w: CGFloat = c.intrinsicContentSize().width for c in v {
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero let w: CGFloat = c.intrinsicContentSize().width
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1 let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
contentView.grid.columns -= c.grid.columns
titleView.addSubview(c)
titleView.grid.views?.append(c) titleView.addSubview(c)
} titleView.grid.views?.append(c)
} }
}
titleView.addSubview(contentView)
titleView.grid.views?.append(contentView) titleView.addSubview(contentView)
titleView.grid.views?.append(contentView)
// rightControls
if let v: Array<UIControl> = item.rightControls { // rightControls
for c in v { if let v: Array<UIControl> = item.rightControls {
let w: CGFloat = c.intrinsicContentSize().width for c in v {
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero let w: CGFloat = c.intrinsicContentSize().width
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1 let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
contentView.grid.columns -= c.grid.columns
titleView.addSubview(c)
titleView.grid.views?.append(c) titleView.addSubview(c)
} titleView.grid.views?.append(c)
} }
}
titleView.grid.contentInset = contentInset
titleView.grid.interimSpace = interimSpace titleView.grid.contentInset = contentInset
titleView.grid.reload() titleView.grid.interimSpace = interimSpace
titleView.grid.reload()
// contentView alignment.
if nil != item.title && "" != item.title { // contentView alignment.
if nil == item.titleLabel.superview { if nil != item.title && "" != item.title {
contentView.addSubview(item.titleLabel) if nil == item.titleLabel.superview {
} contentView.addSubview(item.titleLabel)
item.titleLabel.frame = contentView.bounds }
} else { item.titleLabel.frame = contentView.bounds
item.titleLabel.removeFromSuperview() } else {
} item.titleLabel.removeFromSuperview()
}
if nil != item.detail && "" != item.detail {
if nil == item.detailLabel.superview { if nil != item.detail && "" != item.detail {
contentView.addSubview(item.detailLabel) if nil == item.detailLabel.superview {
} contentView.addSubview(item.detailLabel)
}
if nil == item.titleLabel.superview {
item.detailLabel.frame = contentView.bounds if nil == item.titleLabel.superview {
} else { item.detailLabel.frame = contentView.bounds
item.titleLabel.sizeToFit() } else {
item.detailLabel.sizeToFit() item.titleLabel.sizeToFit()
item.detailLabel.sizeToFit()
let diff: CGFloat = (contentView.frame.height - item.titleLabel.frame.height - item.detailLabel.frame.height) / 2
let diff: CGFloat = (contentView.frame.height - item.titleLabel.frame.height - item.detailLabel.frame.height) / 2
item.titleLabel.frame.size.height += diff
item.titleLabel.frame.size.width = contentView.frame.width item.titleLabel.frame.size.height += diff
item.titleLabel.frame.size.width = contentView.frame.width
item.detailLabel.frame.size.height += diff
item.detailLabel.frame.size.width = contentView.frame.width item.detailLabel.frame.size.height += diff
item.detailLabel.frame.origin.y = item.titleLabel.frame.height item.detailLabel.frame.size.width = contentView.frame.width
} item.detailLabel.frame.origin.y = item.titleLabel.frame.height
} else { }
item.detailLabel.removeFromSuperview() } else {
} item.detailLabel.removeFromSuperview()
}
contentView.grid.reload()
} contentView.grid.reload()
} }
} }
}
} }
/** /**
...@@ -336,16 +335,16 @@ public class NavigationBar : UINavigationBar { ...@@ -336,16 +335,16 @@ public class NavigationBar : UINavigationBar {
when subclassing. when subclassing.
*/ */
public func prepareView() { public func prepareView() {
barStyle = .Black barStyle = .black
translucent = false isTranslucent = false
depth = .depth1 depthPreset = .depth1
interimSpacePreset = .interimSpace1 interimSpacePreset = .interimSpace1
contentEdgeInsetsPreset = .Square1 contentEdgeInsetsPreset = .square1
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
backButtonImage = Icon.cm.arrowBack 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 shadowImage = image
setBackgroundImage(image, forBarMetrics: .Default) setBackgroundImage(image, for: .default)
backgroundColor = Color.white backgroundColor = Color.white
} }
...@@ -379,7 +378,7 @@ public class NavigationBar : UINavigationBar { ...@@ -379,7 +378,7 @@ public class NavigationBar : UINavigationBar {
if nil == item.contentView { if nil == item.contentView {
item.contentView = UIView(frame: CGRect.zero) item.contentView = UIView(frame: CGRect.zero)
} }
item.contentView!.grid.axis.direction = .Vertical item.contentView!.grid.axis.direction = .vertical
return item.contentView! return item.contentView!
} }
} }
...@@ -45,7 +45,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -45,7 +45,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
- Parameter nibNameOrNil: An Optional String for the nib. - Parameter nibNameOrNil: An Optional String for the nib.
- Parameter bundle: An Optional NSBundle where the nib is located. - 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) super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
} }
...@@ -58,15 +58,15 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -58,15 +58,15 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
setViewControllers([rootViewController], animated: false) setViewControllers([rootViewController], animated: false)
} }
public override func viewWillAppear(animated: Bool) { public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
if let v: UIGestureRecognizer = interactivePopGestureRecognizer { if let v: UIGestureRecognizer = interactivePopGestureRecognizer {
if let x: NavigationDrawerController = navigationDrawerController { if let x: NavigationDrawerController = navigationDrawerController {
if let l: UIPanGestureRecognizer = x.leftPanGesture { if let l: UIPanGestureRecognizer = x.leftPanGesture {
l.requireGestureRecognizerToFail(v) l.require(toFail: v)
} }
if let r: UIPanGestureRecognizer = x.rightPanGesture { if let r: UIPanGestureRecognizer = x.rightPanGesture {
r.requireGestureRecognizerToFail(v) r.require(toFail: v)
} }
} }
} }
...@@ -77,12 +77,12 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -77,12 +77,12 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
prepareView() prepareView()
} }
public override func viewDidAppear(animated: Bool) { public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated) super.viewDidAppear(animated)
// Load the initial topItem. // Load the initial topItem.
if let v: NavigationBar = navigationBar as? NavigationBar { if let v: NavigationBar = navigationBar as? NavigationBar {
if let item: UINavigationItem = v.topItem { if let item: UINavigationItem = v.topItem {
v.layoutNavigationItem(item) v.layoutNavigationItem(item: item)
} }
} }
} }
...@@ -94,7 +94,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -94,7 +94,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
- Parameter touch: The UITouch event. - Parameter touch: The UITouch event.
- Returns: A Boolean of whether to continue the gesture or not, true yes, false no. - 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 return interactivePopGestureRecognizer == gestureRecognizer && nil != navigationBar.backItem
} }
...@@ -110,9 +110,8 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -110,9 +110,8 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
if let v: NavigationBar = navigationBar as? NavigationBar { if let v: NavigationBar = navigationBar as? NavigationBar {
let backButton: IconButton = IconButton() let backButton: IconButton = IconButton()
backButton.pulseColor = Color.white backButton.pulseColor = Color.white
backButton.setImage(v.backButtonImage, forState: .Normal) backButton.setImage(v.backButtonImage, for: .highlighted)
backButton.setImage(v.backButtonImage, forState: .Highlighted) backButton.addTarget(self, action: #selector(handleBackButton), for: .touchUpInside)
backButton.addTarget(self, action: #selector(handleBackButton), forControlEvents: .TouchUpInside)
if var c: Array<UIControl> = item.leftControls { if var c: Array<UIControl> = item.leftControls {
c.append(backButton) c.append(backButton)
...@@ -122,14 +121,14 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -122,14 +121,14 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
} }
item.backButton = backButton item.backButton = backButton
v.layoutNavigationItem(item) v.layoutNavigationItem(item: item)
} }
return true return true
} }
/// Handler for the back button. /// Handler for the back button.
internal func handleBackButton() { internal func handleBackButton() {
popViewControllerAnimated(true) popViewController(animated: true)
} }
/** /**
...@@ -145,7 +144,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD ...@@ -145,7 +144,7 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
// This ensures the panning gesture is available when going back between views. // This ensures the panning gesture is available when going back between views.
if let v: UIGestureRecognizer = interactivePopGestureRecognizer { if let v: UIGestureRecognizer = interactivePopGestureRecognizer {
v.enabled = true v.isEnabled = true
v.delegate = self v.delegate = self
} }
} }
......
...@@ -67,15 +67,15 @@ public class MaterialAssociatedObjectNavigationItem { ...@@ -67,15 +67,15 @@ public class MaterialAssociatedObjectNavigationItem {
/// Prepares the titleLabel. /// Prepares the titleLabel.
private func prepareTitleLabel() { private func prepareTitleLabel() {
titleLabel = UILabel() titleLabel = UILabel()
titleLabel.font = RobotoFont.mediumWithSize(17) titleLabel.font = RobotoFont.mediumWithSize(size: 17)
titleLabel.textAlignment = .Center titleLabel.textAlignment = .center
} }
/// Prepares the detailLabel. /// Prepares the detailLabel.
private func prepareDetailLabel() { private func prepareDetailLabel() {
detailLabel = UILabel() detailLabel = UILabel()
detailLabel.font = RobotoFont.regularWithSize(12) detailLabel.font = RobotoFont.regularWithSize(size: 12)
detailLabel.textAlignment = .Center detailLabel.textAlignment = .center
} }
} }
...@@ -83,12 +83,12 @@ public extension UINavigationItem { ...@@ -83,12 +83,12 @@ public extension UINavigationItem {
/// NavigationItem reference. /// NavigationItem reference.
public internal(set) var item: MaterialAssociatedObjectNavigationItem { public internal(set) var item: MaterialAssociatedObjectNavigationItem {
get { get {
return AssociatedObject(self, key: &MaterialAssociatedObjectNavigationItemKey) { return AssociatedObject(base: self, key: &MaterialAssociatedObjectNavigationItemKey) {
return MaterialAssociatedObjectNavigationItem() return MaterialAssociatedObjectNavigationItem()
} }
} }
set(value) { set(value) {
AssociateObject(self, key: &MaterialAssociatedObjectNavigationItemKey, value: value) AssociateObject(base: self, key: &MaterialAssociatedObjectNavigationItemKey, value: value)
} }
} }
......
...@@ -114,21 +114,21 @@ public class RootController : UIViewController { ...@@ -114,21 +114,21 @@ public class RootController : UIViewController {
to the toViewController has completed. to the toViewController has completed.
*/ */
public func transitionFromRootViewController(toViewController: UIViewController, duration: TimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { 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) addChildViewController(toViewController)
toViewController.view.frame = rootViewController.view.frame toViewController.view.frame = rootViewController.view.frame
transitionFromViewController(rootViewController, transition(from: rootViewController,
toViewController: toViewController, to: toViewController,
duration: duration, duration: duration,
options: options, options: options,
animations: animations, animations: animations,
completion: { [weak self] (result: Bool) in completion: { [weak self] (result: Bool) in
if let s: RootController = self { if let s: RootController = self {
toViewController.didMoveToParentViewController(s) toViewController.didMove(toParentViewController: s)
s.rootViewController.removeFromParentViewController() s.rootViewController.removeFromParentViewController()
s.rootViewController = toViewController s.rootViewController = toViewController
s.rootViewController.view.clipsToBounds = true s.rootViewController.view.clipsToBounds = true
s.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] s.rootViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
s.rootViewController.view.contentScaleFactor = Device.scale s.rootViewController.view.contentScaleFactor = Device.scale
completion?(result) completion?(result)
} }
...@@ -157,7 +157,7 @@ public class RootController : UIViewController { ...@@ -157,7 +157,7 @@ public class RootController : UIViewController {
/// A method that prepares the rootViewController. /// A method that prepares the rootViewController.
internal func prepareRootViewController() { internal func prepareRootViewController() {
prepareViewControllerWithinContainer(rootViewController, container: view) prepareViewControllerWithinContainer(viewController: rootViewController, container: view)
} }
/** /**
...@@ -172,9 +172,9 @@ public class RootController : UIViewController { ...@@ -172,9 +172,9 @@ public class RootController : UIViewController {
if let v: UIViewController = viewController { if let v: UIViewController = viewController {
addChildViewController(v) addChildViewController(v)
container.addSubview(v.view) container.addSubview(v.view)
v.didMoveToParentViewController(self) v.didMove(toParentViewController: self)
v.view.clipsToBounds = true v.view.clipsToBounds = true
v.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] v.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
v.view.contentScaleFactor = Device.scale v.view.contentScaleFactor = Device.scale
} }
} }
......
...@@ -40,9 +40,9 @@ public class SearchBar : BarView { ...@@ -40,9 +40,9 @@ public class SearchBar : BarView {
/// Handle the clearButton manually. /// Handle the clearButton manually.
@IBInspectable public var clearButtonAutoHandleEnabled: Bool = true { @IBInspectable public var clearButtonAutoHandleEnabled: Bool = true {
didSet { didSet {
clearButton.removeTarget(self, action: #selector(handleClearButton), forControlEvents: .TouchUpInside) clearButton.removeTarget(self, action: #selector(handleClearButton), for: .touchUpInside)
if clearButtonAutoHandleEnabled { 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 { ...@@ -71,7 +71,7 @@ public class SearchBar : BarView {
@IBInspectable public var placeholder: String? { @IBInspectable public var placeholder: String? {
didSet { didSet {
if let v: String = placeholder { 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 { ...@@ -80,7 +80,7 @@ public class SearchBar : BarView {
@IBInspectable public var placeholderColor: UIColor = Color.darkText.others { @IBInspectable public var placeholderColor: UIColor = Color.darkText.others {
didSet { didSet {
if let v: String = placeholder { 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 { ...@@ -136,7 +136,7 @@ public class SearchBar : BarView {
/// Layout the clearButton. /// Layout the clearButton.
public func layoutClearButton() { public func layoutClearButton() {
let h: CGFloat = textField.frame.height 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. /// Clears the textField text.
...@@ -148,9 +148,9 @@ public class SearchBar : BarView { ...@@ -148,9 +148,9 @@ public class SearchBar : BarView {
private func prepareTextField() { private func prepareTextField() {
textField = UITextField() textField = UITextField()
textField.contentScaleFactor = Device.scale textField.contentScaleFactor = Device.scale
textField.font = RobotoFont.regularWithSize(17) textField.font = RobotoFont.regularWithSize(size: 17)
textField.backgroundColor = Color.clear textField.backgroundColor = Color.clear
textField.clearButtonMode = .WhileEditing textField.clearButtonMode = .whileEditing
tintColor = placeholderColor tintColor = placeholderColor
textColor = Color.darkText.primary textColor = Color.darkText.primary
placeholder = "Search" placeholder = "Search"
...@@ -163,11 +163,10 @@ public class SearchBar : BarView { ...@@ -163,11 +163,10 @@ public class SearchBar : BarView {
clearButton = IconButton() clearButton = IconButton()
clearButton.contentEdgeInsets = UIEdgeInsets.zero clearButton.contentEdgeInsets = UIEdgeInsets.zero
clearButton.tintColor = placeholderColor clearButton.tintColor = placeholderColor
clearButton.setImage(image, forState: .Normal) clearButton.setImage(image, for: .highlighted)
clearButton.setImage(image, forState: .Highlighted)
clearButtonAutoHandleEnabled = true clearButtonAutoHandleEnabled = true
textField.clearButtonMode = .Never textField.clearButtonMode = .never
textField.rightViewMode = .WhileEditing textField.rightViewMode = .whileEditing
textField.rightView = clearButton textField.rightView = clearButton
} }
} }
...@@ -42,7 +42,7 @@ public extension UIViewController { ...@@ -42,7 +42,7 @@ public extension UIViewController {
if viewController is SearchBarController { if viewController is SearchBarController {
return viewController as? SearchBarController return viewController as? SearchBarController
} }
viewController = viewController?.parentViewController viewController = viewController?.parent
} }
return nil return nil
} }
......
...@@ -42,7 +42,7 @@ public extension UIViewController { ...@@ -42,7 +42,7 @@ public extension UIViewController {
if viewController is StatusBarController { if viewController is StatusBarController {
return viewController as? StatusBarController return viewController as? StatusBarController
} }
viewController = viewController?.parentViewController viewController = viewController?.parent
} }
return nil return nil
} }
...@@ -80,7 +80,7 @@ public class StatusBarController : RootController { ...@@ -80,7 +80,7 @@ public class StatusBarController : RootController {
private func prepareStatusBarView() { private func prepareStatusBarView() {
statusBarView = View() statusBarView = View()
statusBarView.zPosition = 3000 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) view.layout(statusBarView).top(0).horizontally().height(20)
} }
} }
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
import UIKit import UIKit
public enum TabBarLineAlignment { public enum TabBarLineAlignment {
case Top case top
case Bottom case bottom
} }
public class TabBar : View { public class TabBar : View {
...@@ -40,7 +40,7 @@ public class TabBar : View { ...@@ -40,7 +40,7 @@ public class TabBar : View {
public private(set) var line: UIView! public private(set) var line: UIView!
/// A value for the line alignment. /// A value for the line alignment.
public var lineAlignment: TabBarLineAlignment = .Bottom { public var lineAlignment: TabBarLineAlignment = .bottom {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
...@@ -79,20 +79,21 @@ public class TabBar : View { ...@@ -79,20 +79,21 @@ public class TabBar : View {
b.grid.columns = columns b.grid.columns = columns
b.contentEdgeInsets = UIEdgeInsets.zero b.contentEdgeInsets = UIEdgeInsets.zero
b.layer.cornerRadius = 0 b.layer.cornerRadius = 0
b.removeTarget(self, action: #selector(handleButton(_:)), forControlEvents: .TouchUpInside) b.removeTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
b.addTarget(self, action: #selector(handleButton(_:)), forControlEvents: .TouchUpInside) b.addTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
} }
grid.views = v as [UIView] 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. /// Handles the button touch event.
@objc
internal func handleButton(button: UIButton) { internal func handleButton(button: UIButton) {
UIView.animateWithDuration(0.25, animations: { [weak self] in UIView.animate(withDuration: 0.25, animations: { [weak self] in
if let s: TabBar = self { if let s = self {
s.line.frame.origin.x = button.frame.origin.x s.line.frame.origin.x = button.frame.origin.x
s.line.frame.size.width = button.frame.size.width s.line.frame.size.width = button.frame.size.width
} }
...@@ -108,7 +109,7 @@ public class TabBar : View { ...@@ -108,7 +109,7 @@ public class TabBar : View {
*/ */
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
autoresizingMask = .FlexibleWidth autoresizingMask = .flexibleWidth
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
prepareBottomLayer() prepareBottomLayer()
} }
......
...@@ -44,7 +44,8 @@ public protocol TextDelegate { ...@@ -44,7 +44,8 @@ public protocol TextDelegate {
- Parameter range: The range of characters that are being - Parameter range: The range of characters that are being
edited. edited.
*/ */
optional func textWillProcessEdit(text: Text, textStorage: TextStorage, string: String, range: NSRange) @objc
optional func textWillProcessEdit(text: Text, textStorage: TextStorage, string: String, range: NSRange)
/** /**
An optional delegation method that is executed after An optional delegation method that is executed after
...@@ -60,7 +61,8 @@ public protocol TextDelegate { ...@@ -60,7 +61,8 @@ public protocol TextDelegate {
- Parameter stop: Halts a service which is either - Parameter stop: Halts a service which is either
publishing or resolving. 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) @objc(Text)
...@@ -111,20 +113,20 @@ public class Text : NSObject { ...@@ -111,20 +113,20 @@ public class Text : NSObject {
/// Prepares the TextStorage regular expression for matching. /// Prepares the TextStorage regular expression for matching.
private func prepareTextStorageExpression() { private func prepareTextStorageExpression() {
textStorage.expression = try? NSRegularExpression(pattern: pattern, options: []) textStorage.expression = try? RegularExpression(pattern: pattern, options: [])
} }
/// Prepares the pre and post processing callbacks. /// Prepares the pre and post processing callbacks.
private func prepareTextStorageProcessingCallbacks() { private func prepareTextStorageProcessingCallbacks() {
textStorage.textWillProcessEdit = { [weak self] (textStorage: TextStorage, string: String, range: NSRange) -> Void in textStorage.textWillProcessEdit = { [weak self] (textStorage: TextStorage, string: String, range: NSRange) -> Void in
if let s: Text = self { 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 { 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)
} }
} }
} }
} }
\ No newline at end of file
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
import UIKit import UIKit
internal typealias TextWillProcessEdit = (TextStorage, String, NSRange) -> Void 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 { public class TextStorage: NSTextStorage {
/// A callback that is executed when a process edit will happen. /// A callback that is executed when a process edit will happen.
...@@ -44,7 +44,7 @@ public class TextStorage: NSTextStorage { ...@@ -44,7 +44,7 @@ public class TextStorage: NSTextStorage {
public lazy var store: NSMutableAttributedString = NSMutableAttributedString() public lazy var store: NSMutableAttributedString = NSMutableAttributedString()
/// The regular expression to match text fragments against. /// The regular expression to match text fragments against.
public var expression: NSRegularExpression? public var expression: RegularExpression?
/// Initializer. /// Initializer.
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
...@@ -63,11 +63,11 @@ public class TextStorage: NSTextStorage { ...@@ -63,11 +63,11 @@ public class TextStorage: NSTextStorage {
/// Processes the text when editing. /// Processes the text when editing.
public override func processEditing() { 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) 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) self.textDidProcessEdit?(self, result, flags, stop)
} }
super.processEditing() super.processEditing()
...@@ -85,8 +85,8 @@ public class TextStorage: NSTextStorage { ...@@ -85,8 +85,8 @@ public class TextStorage: NSTextStorage {
If you don't need this value, pass NULL. If you don't need this value, pass NULL.
- Returns: The attributes for the character at index. - Returns: The attributes for the character at index.
*/ */
public override func attributesAtIndex(location: Int, effectiveRange range: NSRangePointer) -> [String : AnyObject] { public override func attributes(at location: Int, effectiveRange range: NSRangePointer?) -> [String : AnyObject] {
return store.attributesAtIndex(location, effectiveRange: range) return store.attributes(at: location, effectiveRange: range)
} }
/** /**
...@@ -95,9 +95,9 @@ public class TextStorage: NSTextStorage { ...@@ -95,9 +95,9 @@ public class TextStorage: NSTextStorage {
- Parameter str: The string value that the characters - Parameter str: The string value that the characters
will be replaced with. will be replaced with.
*/ */
public override func replaceCharactersInRange(range: NSRange, withString str: String) { public override func replaceCharacters(in range: NSRange, with str: String) {
store.replaceCharactersInRange(range, withString: str) store.replaceCharacters(in: range, with: str)
edited(NSTextStorageEditActions.EditedCharacters, range: range, changeInLength: str.utf16.count - range.length) edited(NSTextStorageEditActions.editedCharacters, range: range, changeInLength: str.utf16.count - range.length)
} }
/** /**
...@@ -106,8 +106,8 @@ public class TextStorage: NSTextStorage { ...@@ -106,8 +106,8 @@ public class TextStorage: NSTextStorage {
- Parameter range: A range of characters that will have their - Parameter range: A range of characters that will have their
attributes updated. 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) store.setAttributes(attrs, range: range)
edited(NSTextStorageEditActions.EditedAttributes, range: range, changeInLength: 0) edited(NSTextStorageEditActions.editedAttributes, range: range, changeInLength: 0)
} }
} }
\ No newline at end of file
...@@ -134,7 +134,7 @@ public class TextView: UITextView { ...@@ -134,7 +134,7 @@ public class TextView: UITextView {
} }
/// An override to the attributedText property. /// An override to the attributedText property.
public override var attributedText: NSAttributedString! { public override var attributedText: AttributedString! {
didSet { didSet {
handleTextViewTextDidChange() handleTextViewTextDidChange()
} }
...@@ -151,7 +151,7 @@ public class TextView: UITextView { ...@@ -151,7 +151,7 @@ public class TextView: UITextView {
} }
/// Text container UIEdgeInset property. /// Text container UIEdgeInset property.
public override var textContainerInset: Insets { public override var textContainerInset: EdgeInsets {
didSet { didSet {
reloadView() reloadView()
} }
...@@ -244,12 +244,12 @@ public class TextView: UITextView { ...@@ -244,12 +244,12 @@ public class TextView: UITextView {
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .none == depth { if .none == depthPreset {
shadowPath = nil shadowPath = nil
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } 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 { ...@@ -265,7 +265,7 @@ public class TextView: UITextView {
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
textContainerInset = EdgeInsets.zero textContainerInset = EdgeInsets.zero
backgroundColor = Color.white backgroundColor = Color.white
masksToBounds = false clipsToBounds = false
removeNotificationHandlers() removeNotificationHandlers()
prepareNotificationHandlers() prepareNotificationHandlers()
reloadView() reloadView()
...@@ -305,9 +305,9 @@ public class TextView: UITextView { ...@@ -305,9 +305,9 @@ public class TextView: UITextView {
v.text = s v.text = s
} }
let h: CGFloat = ceil(v.font.lineHeight) 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 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 { if let s: TextView = self {
v.alpha = 1 v.alpha = 1
v.frame.origin.y = -v.frame.height - s.titleLabelAnimationDistance v.frame.origin.y = -v.frame.height - s.titleLabelAnimationDistance
...@@ -321,7 +321,7 @@ public class TextView: UITextView { ...@@ -321,7 +321,7 @@ public class TextView: UITextView {
private func hideTitleLabel() { private func hideTitleLabel() {
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
if !v.isHidden { if !v.isHidden {
UIView.animateWithDuration(0.25, animations: { UIView.animate(withDuration: 0.25, animations: {
v.alpha = 0 v.alpha = 0
v.frame.origin.y = -v.frame.height v.frame.origin.y = -v.frame.height
}) { _ in }) { _ in
...@@ -333,15 +333,17 @@ public class TextView: UITextView { ...@@ -333,15 +333,17 @@ public class TextView: UITextView {
/// Prepares the Notification handlers. /// Prepares the Notification handlers.
private func prepareNotificationHandlers() { private func prepareNotificationHandlers() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidBegin), name: UITextViewTextDidBeginEditingNotification, object: nil) let defaultCenter = NotificationCenter.default()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidChange), name: UITextViewTextDidChangeNotification, object: nil) defaultCenter.addObserver(self, selector: #selector(handleTextViewTextDidBegin), name: NSNotification.Name.UITextViewTextDidBeginEditing, object: self)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleTextViewTextDidEnd), name: UITextViewTextDidEndEditingNotification, object: nil) 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. /// Removes the Notification handlers.
private func removeNotificationHandlers() { private func removeNotificationHandlers() {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidBeginEditingNotification, object: nil) let defaultCenter = NotificationCenter.default()
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidChangeNotification, object: nil) defaultCenter.removeObserver(self, name: NSNotification.Name.UITextViewTextDidBeginEditing, object: self)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidEndEditingNotification, object: nil) 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 { ...@@ -144,15 +144,15 @@ public class Toolbar : BarView {
private func prepareTitleLabel() { private func prepareTitleLabel() {
titleLabel = UILabel() titleLabel = UILabel()
titleLabel.contentScaleFactor = Device.scale titleLabel.contentScaleFactor = Device.scale
titleLabel.font = RobotoFont.mediumWithSize(17) titleLabel.font = RobotoFont.mediumWithSize(size: 17)
titleLabel.textAlignment = .Left titleLabel.textAlignment = .left
} }
/// Prepares the detailLabel. /// Prepares the detailLabel.
private func prepareDetailLabel() { private func prepareDetailLabel() {
detailLabel = UILabel() detailLabel = UILabel()
detailLabel.contentScaleFactor = Device.scale detailLabel.contentScaleFactor = Device.scale
detailLabel.font = RobotoFont.regularWithSize(12) detailLabel.font = RobotoFont.regularWithSize(size: 12)
detailLabel.textAlignment = .Left detailLabel.textAlignment = .left
} }
} }
...@@ -42,7 +42,7 @@ public extension UIViewController { ...@@ -42,7 +42,7 @@ public extension UIViewController {
if viewController is ToolbarController { if viewController is ToolbarController {
return viewController as? ToolbarController return viewController as? ToolbarController
} }
viewController = viewController?.parentViewController viewController = viewController?.parent
} }
return nil return nil
} }
...@@ -51,16 +51,20 @@ public extension UIViewController { ...@@ -51,16 +51,20 @@ public extension UIViewController {
@objc(ToolbarControllerDelegate) @objc(ToolbarControllerDelegate)
public protocol ToolbarControllerDelegate : MaterialDelegate { public protocol ToolbarControllerDelegate : MaterialDelegate {
/// Delegation method that executes when the floatingViewController will open. /// Delegation method that executes when the floatingViewController will open.
optional func toolbarControllerWillOpenFloatingViewController(toolbarController: ToolbarController) @objc
optional func toolbarControllerWillOpenFloatingViewController(toolbarController: ToolbarController)
/// Delegation method that executes when the floatingViewController will close. /// Delegation method that executes when the floatingViewController will close.
optional func toolbarControllerWillCloseFloatingViewController(toolbarController: ToolbarController) @objc
optional func toolbarControllerWillCloseFloatingViewController(toolbarController: ToolbarController)
/// Delegation method that executes when the floatingViewController did open. /// Delegation method that executes when the floatingViewController did open.
optional func toolbarControllerDidOpenFloatingViewController(toolbarController: ToolbarController) @objc
optional func toolbarControllerDidOpenFloatingViewController(toolbarController: ToolbarController)
/// Delegation method that executes when the floatingViewController did close. /// Delegation method that executes when the floatingViewController did close.
optional func toolbarControllerDidCloseFloatingViewController(toolbarController: ToolbarController) @objc
optional func toolbarControllerDidCloseFloatingViewController(toolbarController: ToolbarController)
} }
@objc(ToolbarController) @objc(ToolbarController)
...@@ -83,26 +87,26 @@ public class ToolbarController : RootController { ...@@ -83,26 +87,26 @@ public class ToolbarController : RootController {
if let v: UIViewController = internalFloatingViewController { if let v: UIViewController = internalFloatingViewController {
v.view.layer.rasterizationScale = Device.scale v.view.layer.rasterizationScale = Device.scale
v.view.layer.shouldRasterize = true v.view.layer.shouldRasterize = true
delegate?.toolbarControllerWillCloseFloatingViewController?(self) delegate?.toolbarControllerWillCloseFloatingViewController?(toolbarController: self)
internalFloatingViewController = nil internalFloatingViewController = nil
UIView.animateWithDuration(0.5, UIView.animate(withDuration: 0.5,
animations: { [weak self] in animations: { [weak self] in
if let s: ToolbarController = self { if let s = self {
v.view.center.y = 2 * s.view.bounds.height v.view.center.y = 2 * s.view.bounds.height
s.toolbar.alpha = 1 s.toolbar.alpha = 1
s.rootViewController.view.alpha = 1 s.rootViewController.view.alpha = 1
} }
}) { [weak self] _ in }) { [weak self] _ in
if let s: ToolbarController = self { if let s = self {
v.willMoveToParentViewController(nil) v.willMove(toParentViewController: nil)
v.view.removeFromSuperview() v.view.removeFromSuperview()
v.removeFromParentViewController() v.removeFromParentViewController()
v.view.layer.shouldRasterize = false v.view.layer.shouldRasterize = false
s.isUserInteractionEnabled = true s.isUserInteractionEnabled = true
s.toolbar.isUserInteractionEnabled = true s.toolbar.isUserInteractionEnabled = true
dispatch_async(dispatch_get_main_queue()) { [weak self] in DispatchQueue.main.async { [weak self] in
if let s: ToolbarController = self { if let s = self {
s.delegate?.toolbarControllerDidCloseFloatingViewController?(s) s.delegate?.toolbarControllerDidCloseFloatingViewController?(toolbarController: s)
} }
} }
} }
...@@ -117,7 +121,7 @@ public class ToolbarController : RootController { ...@@ -117,7 +121,7 @@ public class ToolbarController : RootController {
v.view.isHidden = true v.view.isHidden = true
view.insertSubview(v.view, aboveSubview: toolbar) view.insertSubview(v.view, aboveSubview: toolbar)
v.view.layer.zPosition = 1500 v.view.layer.zPosition = 1500
v.didMoveToParentViewController(self) v.didMove(toParentViewController: self)
// Animate the noteButton out and the noteViewController! in. // Animate the noteButton out and the noteViewController! in.
v.view.isHidden = false v.view.isHidden = false
...@@ -128,21 +132,21 @@ public class ToolbarController : RootController { ...@@ -128,21 +132,21 @@ public class ToolbarController : RootController {
internalFloatingViewController = v internalFloatingViewController = v
isUserInteractionEnabled = false isUserInteractionEnabled = false
toolbar.isUserInteractionEnabled = false toolbar.isUserInteractionEnabled = false
delegate?.toolbarControllerWillOpenFloatingViewController?(self) delegate?.toolbarControllerWillOpenFloatingViewController?(toolbarController: self)
UIView.animateWithDuration(0.5, UIView.animate(withDuration: 0.5,
animations: { [weak self] in animations: { [weak self] in
if let s: ToolbarController = self { if let s = self {
v.view.center.y = s.view.bounds.height / 2 v.view.center.y = s.view.bounds.height / 2
s.toolbar.alpha = 0.5 s.toolbar.alpha = 0.5
s.rootViewController.view.alpha = 0.5 s.rootViewController.view.alpha = 0.5
} }
}) { [weak self] _ in }) { [weak self] _ in
if let s: ToolbarController = self { if let s = self {
v.view.layer.shouldRasterize = false v.view.layer.shouldRasterize = false
s.view.layer.shouldRasterize = false s.view.layer.shouldRasterize = false
dispatch_async(dispatch_get_main_queue()) { [weak self] in DispatchQueue.main.async { [weak self] in
if let s: ToolbarController = self { if let s = self {
s.delegate?.toolbarControllerDidOpenFloatingViewController?(s) s.delegate?.toolbarControllerDidOpenFloatingViewController?(toolbarController: s)
} }
} }
} }
......
...@@ -186,20 +186,6 @@ public class View: UIView { ...@@ -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 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 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