Commit 9a90a7d5 by Daniel Dahan

cleanup and removal of duplicate code

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