Commit f5619913 by Daniel Dahan

updated references from unowned to weak

parent 92a2303a
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
location = "group:Programmatic/MenuView/MenuView.xcodeproj"> location = "group:Programmatic/MenuView/MenuView.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:Programmatic/MenuViewController/MenuViewController.xcodeproj"> location = "group:Programmatic/MenuController/MenuController.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:Programmatic/TabBar/TabBar.xcodeproj"> location = "group:Programmatic/TabBar/TabBar.xcodeproj">
......
...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let navigationController: AppNavigationController = AppNavigationController(rootViewController: RecipesViewController()) let navigationController: AppNavigationController = AppNavigationController(rootViewController: RecipesViewController())
let menuViewController: AppMenuViewController = AppMenuViewController(rootViewController: navigationController) let menuViewController: AppMenuController = AppMenuController(rootViewController: navigationController)
menuViewController.edgesForExtendedLayout = .None menuViewController.edgesForExtendedLayout = .None
let bottomNavigationController: BottomNavigationController = BottomNavigationController() let bottomNavigationController: BottomNavigationController = BottomNavigationController()
......
...@@ -29,16 +29,16 @@ ...@@ -29,16 +29,16 @@
*/ */
/* /*
The following is an example of using a MenuViewController to control the The following is an example of using a MenuController to control the
flow of your application. flow of your application.
*/ */
import UIKit import UIKit
import Material import Material
class AppMenuViewController: MenuViewController { class AppMenuController: MenuController {
/// MenuView diameter. /// MenuView diameter.
private let baseViewSize: CGSize = CGSizeMake(56, 56) private let baseSize: CGSize = CGSizeMake(56, 56)
/// MenuView inset. /// MenuView inset.
private let menuViewInset: CGFloat = 16 private let menuViewInset: CGFloat = 16
...@@ -136,11 +136,11 @@ class AppMenuViewController: MenuViewController { ...@@ -136,11 +136,11 @@ class AppMenuViewController: MenuViewController {
yellowButton.addTarget(self, action: #selector(handleYellowButton), forControlEvents: .TouchUpInside) yellowButton.addTarget(self, action: #selector(handleYellowButton), forControlEvents: .TouchUpInside)
// Initialize the menu and setup the configuration options. // Initialize the menu and setup the configuration options.
menuView.menu.baseViewSize = baseViewSize menuView.menu.baseSize = baseSize
menuView.menu.views = [menuButton, blueButton, greenButton, yellowButton] menuView.menu.views = [menuButton, blueButton, greenButton, yellowButton]
view.addSubview(menuView) view.addSubview(menuView)
MaterialLayout.size(view, child: menuView, width: baseViewSize.width, height: baseViewSize.height) MaterialLayout.size(view, child: menuView, width: baseSize.width, height: baseSize.height)
MaterialLayout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset) MaterialLayout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset)
} }
......
...@@ -104,7 +104,7 @@ extension ViewController: MaterialCollectionViewDataSource { ...@@ -104,7 +104,7 @@ extension ViewController: MaterialCollectionViewDataSource {
} }
/// Returns the number of sections. /// Returns the number of sections.
func numberOfSectionsInCollectionView(tableView: UICollectionView) -> Int { func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1 return 1
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
F6949FC21CB53676000E4C23 /* Embed Frameworks */ = { 966ECF1C1CF4B66F00BB0BDF /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase; isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
dstPath = ""; dstPath = "";
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
96A71E641C6FA6D500C0C4AE /* Sources */, 96A71E641C6FA6D500C0C4AE /* Sources */,
96A71E651C6FA6D500C0C4AE /* Frameworks */, 96A71E651C6FA6D500C0C4AE /* Frameworks */,
96A71E661C6FA6D500C0C4AE /* Resources */, 96A71E661C6FA6D500C0C4AE /* Resources */,
F6949FC21CB53676000E4C23 /* Embed Frameworks */, 966ECF1C1CF4B66F00BB0BDF /* Embed Frameworks */,
); );
buildRules = ( buildRules = (
); );
......
...@@ -75,8 +75,11 @@ class ViewController: UIViewController { ...@@ -75,8 +75,11 @@ class ViewController: UIViewController {
icons.append(Item(name: "clear", mdIcon: MaterialIcon.clear, cmIcon: MaterialIcon.cm.clear)) icons.append(Item(name: "clear", mdIcon: MaterialIcon.clear, cmIcon: MaterialIcon.cm.clear))
icons.append(Item(name: "close", mdIcon: MaterialIcon.close, cmIcon: MaterialIcon.cm.close)) icons.append(Item(name: "close", mdIcon: MaterialIcon.close, cmIcon: MaterialIcon.cm.close))
icons.append(Item(name: "edit", mdIcon: MaterialIcon.edit, cmIcon: MaterialIcon.cm.edit)) icons.append(Item(name: "edit", mdIcon: MaterialIcon.edit, cmIcon: MaterialIcon.cm.edit))
icons.append(Item(name: "history", mdIcon: MaterialIcon.history, cmIcon: nil)) icons.append(Item(name: "favorite", mdIcon: MaterialIcon.favorite, cmIcon: nil))
icons.append(Item(name: "image", mdIcon: MaterialIcon.image, cmIcon: MaterialIcon.cm.image)) icons.append(Item(name: "favoriteBorder", mdIcon: MaterialIcon.favoriteBorder, cmIcon: nil))
icons.append(Item(name: "history", mdIcon: MaterialIcon.history, cmIcon: nil))
icons.append(Item(name: "home", mdIcon: MaterialIcon.home, cmIcon: nil))
icons.append(Item(name: "image", mdIcon: MaterialIcon.image, cmIcon: MaterialIcon.cm.image))
icons.append(Item(name: "menu", mdIcon: MaterialIcon.menu, cmIcon: MaterialIcon.cm.menu)) icons.append(Item(name: "menu", mdIcon: MaterialIcon.menu, cmIcon: MaterialIcon.cm.menu))
icons.append(Item(name: "microphone", mdIcon: nil, cmIcon: MaterialIcon.cm.microphone)) icons.append(Item(name: "microphone", mdIcon: nil, cmIcon: MaterialIcon.cm.microphone))
icons.append(Item(name: "moreVertical", mdIcon: MaterialIcon.moreHorizontal, cmIcon: MaterialIcon.cm.moreHorizontal)) icons.append(Item(name: "moreVertical", mdIcon: MaterialIcon.moreHorizontal, cmIcon: MaterialIcon.cm.moreHorizontal))
......
...@@ -157,7 +157,7 @@ class ViewController: UIViewController { ...@@ -157,7 +157,7 @@ class ViewController: UIViewController {
// Initialize the menu and setup the configuration options. // Initialize the menu and setup the configuration options.
fabMenu = Menu(origin: CGPointMake(view.bounds.width - diameter - spacing, view.bounds.height - diameter - spacing)) fabMenu = Menu(origin: CGPointMake(view.bounds.width - diameter - spacing, view.bounds.height - diameter - spacing))
fabMenu.direction = .Up fabMenu.direction = .Up
fabMenu.baseViewSize = CGSizeMake(diameter, diameter) fabMenu.baseSize = CGSizeMake(diameter, diameter)
fabMenu.views = [btn1, btn2, btn3, btn4] fabMenu.views = [btn1, btn2, btn3, btn4]
} }
...@@ -199,7 +199,7 @@ class ViewController: UIViewController { ...@@ -199,7 +199,7 @@ class ViewController: UIViewController {
flatMenu = Menu(origin: CGPointMake(spacing, view.bounds.height - height - spacing)) flatMenu = Menu(origin: CGPointMake(spacing, view.bounds.height - height - spacing))
flatMenu.direction = .Up flatMenu.direction = .Up
flatMenu.spacing = 8 flatMenu.spacing = 8
flatMenu.itemViewSize = CGSizeMake(120, height) flatMenu.itemSize = CGSizeMake(120, height)
flatMenu.views = [btn1, btn2, btn3, btn4] flatMenu.views = [btn1, btn2, btn3, btn4]
} }
...@@ -233,7 +233,7 @@ class ViewController: UIViewController { ...@@ -233,7 +233,7 @@ class ViewController: UIViewController {
// Initialize the menu and setup the configuration options. // Initialize the menu and setup the configuration options.
flashMenu = Menu(origin: CGPointMake((view.bounds.width + btn1.width) / 2, 100)) flashMenu = Menu(origin: CGPointMake((view.bounds.width + btn1.width) / 2, 100))
flashMenu.direction = .Left flashMenu.direction = .Left
flashMenu.itemViewSize = btn1.intrinsicContentSize() flashMenu.itemSize = btn1.intrinsicContentSize()
flashMenu.views = [btn1, btn2, btn3] flashMenu.views = [btn1, btn2, btn3]
} }
} }
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
<Workspace <Workspace
version = "1.0"> version = "1.0">
<FileRef <FileRef
location = "self:MenuViewController.xcodeproj"> location = "self:MenuController.xcodeproj">
</FileRef> </FileRef>
</Workspace> </Workspace>
...@@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = AppMenuViewController(rootViewController: YellowViewController()) window!.rootViewController = AppMenuController(rootViewController: YellowViewController())
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
return true return true
} }
......
...@@ -29,26 +29,20 @@ ...@@ -29,26 +29,20 @@
*/ */
/* /*
The following is an example of using a MenuViewController to control the The following is an example of using a MenuController to control the
flow of your application. flow of your application.
*/ */
import UIKit import UIKit
import Material import Material
class AppMenuViewController: MenuViewController { class AppMenuController: MenuController {
/// MenuView diameter. /// MenuView diameter.
private let baseViewSize: CGSize = CGSizeMake(56, 56) private let baseSize: CGSize = CGSizeMake(56, 56)
/// MenuView inset. /// MenuView inset.
private let menuViewInset: CGFloat = 16 private let menuViewInset: CGFloat = 16
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareMenuView()
}
/// Loads the BlueViewController into the menuViewControllers rootViewController. /// Loads the BlueViewController into the menuViewControllers rootViewController.
func handleBlueButton() { func handleBlueButton() {
if rootViewController is BlueViewController { if rootViewController is BlueViewController {
...@@ -94,8 +88,10 @@ class AppMenuViewController: MenuViewController { ...@@ -94,8 +88,10 @@ class AppMenuViewController: MenuViewController {
} }
/// Prepares view. /// Prepares view.
private func prepareView() { override func prepareView() {
super.prepareView()
view.backgroundColor = MaterialColor.black view.backgroundColor = MaterialColor.black
prepareMenuView()
} }
/// Prepares the add button. /// Prepares the add button.
...@@ -132,11 +128,11 @@ class AppMenuViewController: MenuViewController { ...@@ -132,11 +128,11 @@ class AppMenuViewController: MenuViewController {
btn4.addTarget(self, action: #selector(handleYellowButton), forControlEvents: .TouchUpInside) btn4.addTarget(self, action: #selector(handleYellowButton), forControlEvents: .TouchUpInside)
// Initialize the menu and setup the configuration options. // Initialize the menu and setup the configuration options.
menuView.menu.baseViewSize = baseViewSize menuView.menu.baseSize = baseSize
menuView.menu.views = [btn1, btn2, btn3, btn4] menuView.menu.views = [btn1, btn2, btn3, btn4]
view.addSubview(menuView) view.addSubview(menuView)
MaterialLayout.size(view, child: menuView, width: baseViewSize.width, height: baseViewSize.height) MaterialLayout.size(view, child: menuView, width: baseSize.width, height: baseSize.height)
MaterialLayout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset) MaterialLayout.alignFromBottomRight(view, child: menuView, bottom: menuViewInset, right: menuViewInset)
} }
} }
......
...@@ -134,7 +134,7 @@ class ViewController: UIViewController { ...@@ -134,7 +134,7 @@ class ViewController: UIViewController {
// Initialize the menu and setup the configuration options. // Initialize the menu and setup the configuration options.
menuView.menu.direction = .Up menuView.menu.direction = .Up
menuView.menu.baseViewSize = CGSizeMake(diameter, diameter) menuView.menu.baseSize = CGSizeMake(diameter, diameter)
menuView.menu.views = [btn1, btn2, btn3, btn4] menuView.menu.views = [btn1, btn2, btn3, btn4]
view.addSubview(menuView) view.addSubview(menuView)
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_favorite_border_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_favorite_border_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_favorite_border_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_favorite_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_favorite_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_favorite_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_home_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_home_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_home_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
...@@ -108,14 +108,16 @@ public class BarViewController : UIViewController { ...@@ -108,14 +108,16 @@ public class BarViewController : UIViewController {
duration: duration, duration: duration,
options: options, options: options,
animations: animations, animations: animations,
completion: { [unowned self] (result: Bool) in completion: { [weak self] (result: Bool) in
toViewController.didMoveToParentViewController(self) if let s: BarViewController = self {
self.rootViewController.removeFromParentViewController() toViewController.didMoveToParentViewController(s)
self.rootViewController = toViewController s.rootViewController.removeFromParentViewController()
self.rootViewController.view.clipsToBounds = true s.rootViewController = toViewController
self.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] s.rootViewController.view.clipsToBounds = true
self.view.sendSubviewToBack(self.rootViewController.view) s.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
completion?(result) s.view.sendSubviewToBack(s.rootViewController.view)
completion?(result)
}
}) })
} }
......
...@@ -579,12 +579,14 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -579,12 +579,14 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
dispatch_async(sessionQueue) { dispatch_async(sessionQueue) {
if let v: AVCaptureConnection = self.imageOutput.connectionWithMediaType(AVMediaTypeVideo) { if let v: AVCaptureConnection = self.imageOutput.connectionWithMediaType(AVMediaTypeVideo) {
v.videoOrientation = self.currentVideoOrientation v.videoOrientation = self.currentVideoOrientation
self.imageOutput.captureStillImageAsynchronouslyFromConnection(v) { [unowned self] (sampleBuffer: CMSampleBuffer!, error: NSError!) -> Void in self.imageOutput.captureStillImageAsynchronouslyFromConnection(v) { [weak self] (sampleBuffer: CMSampleBuffer!, error: NSError!) -> Void in
if nil == error { if let s: CaptureSession = self {
let data: NSData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) if nil == error {
self.delegate?.captureStillImageAsynchronously?(self, image: UIImage(data: data)!) let data: NSData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
} else { s.delegate?.captureStillImageAsynchronously?(s, image: UIImage(data: data)!)
self.delegate?.captureStillImageAsynchronouslyFailedWithError?(self, error: error!) } else {
s.delegate?.captureStillImageAsynchronouslyFailedWithError?(s, error: error!)
}
} }
} }
} }
......
...@@ -75,7 +75,7 @@ public class MaterialCollectionView : UICollectionView { ...@@ -75,7 +75,7 @@ public class MaterialCollectionView : UICollectionView {
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset { public var contentInsetPreset: MaterialEdgeInset {
get { get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset return (collectionViewLayout as! MaterialCollectionViewLayout).contentInsetPreset
} }
set(value) { set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset = value (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset = value
...@@ -84,20 +84,20 @@ public class MaterialCollectionView : UICollectionView { ...@@ -84,20 +84,20 @@ public class MaterialCollectionView : UICollectionView {
public override var contentInset: UIEdgeInsets { public override var contentInset: UIEdgeInsets {
get { get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset return (collectionViewLayout as! MaterialCollectionViewLayout).contentInset
} }
set(value) { set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset = value (collectionViewLayout as! MaterialCollectionViewLayout).contentInset = value
} }
} }
/// Scroll direction. /// Scroll direction.
public var scrollDirection: UICollectionViewScrollDirection { public var scrollDirection: UICollectionViewScrollDirection {
get { get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.scrollDirection return (collectionViewLayout as! MaterialCollectionViewLayout).scrollDirection
} }
set(value) { set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.scrollDirection = value (collectionViewLayout as! MaterialCollectionViewLayout).scrollDirection = value
} }
} }
...@@ -111,10 +111,20 @@ public class MaterialCollectionView : UICollectionView { ...@@ -111,10 +111,20 @@ public class MaterialCollectionView : UICollectionView {
/// Spacing between items. /// Spacing between items.
@IBInspectable public var spacing: CGFloat { @IBInspectable public var spacing: CGFloat {
get { get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.spacing return (collectionViewLayout as! MaterialCollectionViewLayout).spacing
} }
set(value) { set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.spacing = value (collectionViewLayout as! MaterialCollectionViewLayout).spacing = value
}
}
/// The layout alignment direction.
public var alignmentDirection: MaterialAlignmentDirection {
get {
return (collectionViewLayout as! MaterialCollectionViewLayout).alignmentDirection
}
set(value) {
(collectionViewLayout as! MaterialCollectionViewLayout).alignmentDirection = value
} }
} }
...@@ -132,7 +142,10 @@ public class MaterialCollectionView : UICollectionView { ...@@ -132,7 +142,10 @@ public class MaterialCollectionView : UICollectionView {
- Parameter collectionViewLayout: A UICollectionViewLayout reference. - Parameter collectionViewLayout: A UICollectionViewLayout reference.
*/ */
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) { public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout) guard let l = layout as? MaterialCollectionViewLayout else {
assert(false, "[MaterialCollectionView Error: Must use a class that subclasses MaterialCollectionViewLayout]")
}
super.init(frame: frame, collectionViewLayout: l)
prepareView() prepareView()
} }
...@@ -161,5 +174,6 @@ public class MaterialCollectionView : UICollectionView { ...@@ -161,5 +174,6 @@ public class MaterialCollectionView : UICollectionView {
contentScaleFactor = MaterialDevice.scale contentScaleFactor = MaterialDevice.scale
backgroundColor = MaterialColor.clear backgroundColor = MaterialColor.clear
contentInset = UIEdgeInsetsZero contentInset = UIEdgeInsetsZero
alignmentDirection = .None
} }
} }
...@@ -30,13 +30,16 @@ ...@@ -30,13 +30,16 @@
import UIKit import UIKit
public class MaterialCollectionViewLayout : UICollectionViewLayout { public enum MaterialAlignmentDirection {
case None
case Vertical
case Horizontal
}
public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
/// Used to calculate the dimensions of the cells. /// Used to calculate the dimensions of the cells.
internal var offset: CGPoint = CGPointZero internal var offset: CGPoint = CGPointZero
/// The size of items.
public var itemSize: CGSize = CGSizeZero
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset = .None { public var contentInsetPreset: MaterialEdgeInset = .None {
didSet { didSet {
...@@ -56,8 +59,8 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout { ...@@ -56,8 +59,8 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
/// Cell items. /// Cell items.
public private(set) var items: Array<MaterialDataSourceItem>? public private(set) var items: Array<MaterialDataSourceItem>?
/// Scroll direction. /// Alignment direction.
public var scrollDirection: UICollectionViewScrollDirection = .Vertical public var alignmentDirection: MaterialAlignmentDirection = .None
/// A preset wrapper around spacing. /// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None { public var spacingPreset: MaterialSpacing = .None {
...@@ -85,30 +88,48 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout { ...@@ -85,30 +88,48 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
} }
public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath) let attributes: UICollectionViewLayoutAttributes = super.layoutAttributesForItemAtIndexPath(indexPath)!
let item: MaterialDataSourceItem = items![indexPath.item] let item: MaterialDataSourceItem = items![indexPath.item]
if 0 < itemSize.width && 0 < itemSize.height { switch alignmentDirection {
attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, itemSize.height - contentInset.top - contentInset.bottom) case .Vertical:
} 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 = CGRectMake(contentInset.left, offset.y, collectionView!.bounds.width - contentInset.left - contentInset.right, nil == item.height ? collectionView!.bounds.height : item.height!) case .Horizontal:
} 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 = CGRectMake(offset.x, contentInset.top, nil == item.width ? collectionView!.bounds.width : item.width!, collectionView!.bounds.height - contentInset.top - contentInset.bottom)
case .None:
attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, itemSize.height - contentInset.top - contentInset.bottom)
} }
return attributes return attributes
} }
public override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { public override func layoutAttributesForSupplementaryViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
var layoutAttributes: Array<UICollectionViewLayoutAttributes> = Array<UICollectionViewLayoutAttributes>() let attributes: UICollectionViewLayoutAttributes = super.layoutAttributesForSupplementaryViewOfKind(elementKind, atIndexPath: indexPath)!
for (attribute, _) in layoutItems { let item: MaterialDataSourceItem = items![indexPath.item]
if CGRectIntersectsRect(rect, attribute.frame) {
layoutAttributes.append(attribute) switch alignmentDirection {
} case .Vertical:
attributes.frame = CGRectMake(contentInset.left, offset.y, collectionView!.bounds.width - contentInset.left - contentInset.right, 44)
case .Horizontal:
attributes.frame = CGRectMake(offset.x, contentInset.top, nil == item.width ? collectionView!.bounds.width : item.width!, 44)
case .None:
attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, headerReferenceSize.height - contentInset.top - contentInset.bottom)
} }
return layoutAttributes
return attributes
} }
public override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributes: Array<UICollectionViewLayoutAttributes> = super.layoutAttributesForElementsInRect(rect)!
return attributes
}
public override func layoutAttributesForDecorationViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = super.layoutAttributesForDecorationViewOfKind(elementKind, atIndexPath: indexPath)!
return attributes
}
public override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool { public override func shouldInvalidateLayoutForBoundsChange(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
} }
...@@ -118,8 +139,9 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout { ...@@ -118,8 +139,9 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
} }
public override func prepareLayout() { public override func prepareLayout() {
let dataSource: MaterialCollectionViewDataSource = collectionView!.dataSource as! MaterialCollectionViewDataSource if let dataSource: MaterialCollectionViewDataSource = collectionView?.dataSource as? MaterialCollectionViewDataSource {
prepareLayoutForItems(dataSource.items()) prepareLayoutForItems(dataSource.items())
}
} }
public func prepareLayoutForItems(items: Array<MaterialDataSourceItem>) { public func prepareLayoutForItems(items: Array<MaterialDataSourceItem>) {
...@@ -146,12 +168,13 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout { ...@@ -146,12 +168,13 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
offset.x += contentInset.right - spacing offset.x += contentInset.right - spacing
offset.y += contentInset.bottom - spacing offset.y += contentInset.bottom - spacing
if 0 < itemSize.width && 0 < itemSize.height { switch alignmentDirection {
contentSize = CGSizeMake(offset.x, offset.y) case .Vertical:
} else if .Vertical == scrollDirection {
contentSize = CGSizeMake(collectionView!.bounds.width, offset.y) contentSize = CGSizeMake(collectionView!.bounds.width, offset.y)
} else { case .Horizontal:
contentSize = CGSizeMake(offset.x, collectionView!.bounds.height) contentSize = CGSizeMake(offset.x, collectionView!.bounds.height)
case .None:
contentSize = CGSizeMake(offset.x, offset.y)
} }
} }
......
...@@ -66,8 +66,11 @@ public struct MaterialIcon { ...@@ -66,8 +66,11 @@ public struct MaterialIcon {
public static let clear: UIImage? = MaterialIcon.icon("ic_close_white") public static let clear: UIImage? = MaterialIcon.icon("ic_close_white")
public static let close: UIImage? = MaterialIcon.icon("ic_close_white") public static let close: UIImage? = MaterialIcon.icon("ic_close_white")
public static let edit: UIImage? = MaterialIcon.icon("ic_edit_white") public static let edit: UIImage? = MaterialIcon.icon("ic_edit_white")
public static let history: UIImage? = MaterialIcon.icon("ic_history_white") public static let favorite: UIImage? = MaterialIcon.icon("ic_favorite_white")
public static let image: UIImage? = MaterialIcon.icon("ic_image_white") public static let favoriteBorder: UIImage? = MaterialIcon.icon("ic_favorite_border_white")
public static let history: UIImage? = MaterialIcon.icon("ic_history_white")
public static let home: UIImage? = MaterialIcon.icon("ic_home_white")
public static let image: UIImage? = MaterialIcon.icon("ic_image_white")
public static let menu: UIImage? = MaterialIcon.icon("ic_menu_white") public static let menu: UIImage? = MaterialIcon.icon("ic_menu_white")
public static let moreHorizontal: UIImage? = MaterialIcon.icon("ic_more_horiz_white") public static let moreHorizontal: UIImage? = MaterialIcon.icon("ic_more_horiz_white")
public static let moreVertical: UIImage? = MaterialIcon.icon("ic_more_vert_white") public static let moreVertical: UIImage? = MaterialIcon.icon("ic_more_vert_white")
......
...@@ -373,10 +373,12 @@ public class MaterialSwitch : UIControl { ...@@ -373,10 +373,12 @@ public class MaterialSwitch : UIControl {
if enabled && internalSwitchState != state { if enabled && internalSwitchState != state {
internalSwitchState = state internalSwitchState = state
if animated { if animated {
animateToState(state) { [unowned self] _ in animateToState(state) { [weak self] _ in
self.sendActionsForControlEvents(.ValueChanged) if let s: MaterialSwitch = self {
completion?(control: self) s.sendActionsForControlEvents(.ValueChanged)
self.delegate?.materialSwitchStateChanged(self) completion?(control: s)
s.delegate?.materialSwitchStateChanged(s)
}
} }
} else { } else {
button.x = .On == state ? self.onPosition : self.offPosition button.x = .On == state ? self.onPosition : self.offPosition
...@@ -545,16 +547,22 @@ public class MaterialSwitch : UIControl { ...@@ -545,16 +547,22 @@ public class MaterialSwitch : UIControl {
UIView.animateWithDuration(0.15, UIView.animateWithDuration(0.15,
delay: 0.05, delay: 0.05,
options: .CurveEaseInOut, options: .CurveEaseInOut,
animations: { [unowned self] in animations: { [weak self] in
self.button.x = .On == state ? self.onPosition + self.bounceOffset : self.offPosition - self.bounceOffset if let s: MaterialSwitch = self {
self.styleForState(state) s.button.x = .On == state ? s.onPosition + s.bounceOffset : s.offPosition - s.bounceOffset
}) { [unowned self] _ in s.styleForState(state)
}
}) { [weak self] _ in
UIView.animateWithDuration(0.15, UIView.animateWithDuration(0.15,
animations: { [unowned self] in animations: { [weak self] in
self.button.x = .On == state ? self.onPosition : self.offPosition if let s: MaterialSwitch = self {
}) { [unowned self] _ in s.button.x = .On == state ? s.onPosition : s.offPosition
self.userInteractionEnabled = true }
completion?(control: self) }) { [weak self] _ in
if let s: MaterialSwitch = self {
s.userInteractionEnabled = true
completion?(control: s)
}
} }
} }
} }
......
...@@ -80,10 +80,10 @@ public class Menu { ...@@ -80,10 +80,10 @@ public class Menu {
} }
/// Size of views, not including the first view. /// Size of views, not including the first view.
public var itemViewSize: CGSize = CGSizeMake(48, 48) public var itemSize: CGSize = CGSizeMake(48, 48)
/// An Optional base view size. /// An Optional base view size.
public var baseViewSize: CGSize? public var baseSize: CGSize?
/** /**
Initializer. Initializer.
...@@ -178,13 +178,17 @@ public class Menu { ...@@ -178,13 +178,17 @@ public class Menu {
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [weak self] in
view.alpha = 1 if let s: Menu = self {
view.frame.origin.y = base!.frame.origin.y - CGFloat(i) * self.itemViewSize.height - CGFloat(i) * self.spacing view.alpha = 1
animations?(view) view.frame.origin.y = base!.frame.origin.y - CGFloat(i) * s.itemSize.height - CGFloat(i) * s.spacing
}) { [unowned self] _ in animations?(view)
completion?(view) }
self.enable(view) }) { [weak self] _ in
if let s: Menu = self {
completion?(view)
s.enable(view)
}
} }
} }
opened = true opened = true
...@@ -211,14 +215,18 @@ public class Menu { ...@@ -211,14 +215,18 @@ public class Menu {
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [weak self] in
view.alpha = 0 if let s: Menu = self {
view.frame.origin.y = self.origin.y view.alpha = 0
animations?(view) view.frame.origin.y = s.origin.y
}) { [unowned self] _ in animations?(view)
view.hidden = true }
completion?(view) }) { [weak self] _ in
self.enable(view) if let s: Menu = self {
view.hidden = true
completion?(view)
s.enable(view)
}
} }
} }
opened = false opened = false
...@@ -246,19 +254,23 @@ public class Menu { ...@@ -246,19 +254,23 @@ public class Menu {
let view: UIView = v[i] let view: UIView = v[i]
view.hidden = false view.hidden = false
let h: CGFloat = nil == baseViewSize ? itemViewSize.height : baseViewSize!.height let h: CGFloat = nil == baseSize ? itemSize.height : baseSize!.height
UIView.animateWithDuration(Double(i) * duration, UIView.animateWithDuration(Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [weak self] in
view.alpha = 1 if let s: Menu = self {
view.frame.origin.y = base!.frame.origin.y + h + CGFloat(i - 1) * self.itemViewSize.height + CGFloat(i) * self.spacing view.alpha = 1
animations?(view) view.frame.origin.y = base!.frame.origin.y + h + CGFloat(i - 1) * s.itemSize.height + CGFloat(i) * s.spacing
}) { [unowned self] _ in animations?(view)
completion?(view) }
self.enable(view) }) { [weak self] _ in
if let s: Menu = self {
completion?(view)
s.enable(view)
}
} }
} }
opened = true opened = true
...@@ -280,20 +292,24 @@ public class Menu { ...@@ -280,20 +292,24 @@ public class Menu {
for i in 1..<v.count { for i in 1..<v.count {
let view: UIView = v[i] let view: UIView = v[i]
let h: CGFloat = nil == baseViewSize ? itemViewSize.height : baseViewSize!.height let h: CGFloat = nil == baseSize ? itemSize.height : baseSize!.height
UIView.animateWithDuration(Double(i) * duration, UIView.animateWithDuration(Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [weak self] in
view.alpha = 0 if let s: Menu = self {
view.frame.origin.y = self.origin.y + h view.alpha = 0
animations?(view) view.frame.origin.y = s.origin.y + h
}) { [unowned self] _ in animations?(view)
view.hidden = true }
completion?(view) }) { [weak self] _ in
self.enable(view) if let s: Menu = self {
view.hidden = true
completion?(view)
s.enable(view)
}
} }
} }
opened = false opened = false
...@@ -326,13 +342,17 @@ public class Menu { ...@@ -326,13 +342,17 @@ public class Menu {
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [weak self] in
view.alpha = 1 if let s: Menu = self {
view.frame.origin.x = base!.frame.origin.x - CGFloat(i) * self.itemViewSize.width - CGFloat(i) * self.spacing view.alpha = 1
animations?(view) view.frame.origin.x = base!.frame.origin.x - CGFloat(i) * s.itemSize.width - CGFloat(i) * s.spacing
}) { [unowned self] _ in animations?(view)
completion?(view) }
self.enable(view) }) { [weak self] _ in
if let s: Menu = self {
completion?(view)
s.enable(view)
}
} }
} }
opened = true opened = true
...@@ -358,14 +378,18 @@ public class Menu { ...@@ -358,14 +378,18 @@ public class Menu {
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [weak self] in
view.alpha = 0 if let s: Menu = self {
view.frame.origin.x = self.origin.x view.alpha = 0
animations?(view) view.frame.origin.x = s.origin.x
}) { [unowned self] _ in animations?(view)
view.hidden = true }
completion?(view) }) { [weak self] _ in
self.enable(view) if let s: Menu = self {
view.hidden = true
completion?(view)
s.enable(view)
}
} }
} }
opened = false opened = false
...@@ -392,19 +416,23 @@ public class Menu { ...@@ -392,19 +416,23 @@ public class Menu {
let view: UIView = v[i] let view: UIView = v[i]
view.hidden = false view.hidden = false
let h: CGFloat = nil == baseViewSize ? itemViewSize.height : baseViewSize!.height let h: CGFloat = nil == baseSize ? itemSize.height : baseSize!.height
UIView.animateWithDuration(Double(i) * duration, UIView.animateWithDuration(Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [weak self] in
view.alpha = 1 if let s: Menu = self {
view.frame.origin.x = base!.frame.origin.x + h + CGFloat(i - 1) * self.itemViewSize.width + CGFloat(i) * self.spacing view.alpha = 1
animations?(view) view.frame.origin.x = base!.frame.origin.x + h + CGFloat(i - 1) * s.itemSize.width + CGFloat(i) * s.spacing
}) { [unowned self] _ in animations?(view)
completion?(view) }
self.enable(view) }) { [weak self] _ in
if let s: Menu = self {
completion?(view)
s.enable(view)
}
} }
} }
opened = true opened = true
...@@ -426,20 +454,24 @@ public class Menu { ...@@ -426,20 +454,24 @@ public class Menu {
for i in 1..<v.count { for i in 1..<v.count {
let view: UIView = v[i] let view: UIView = v[i]
let w: CGFloat = nil == baseViewSize ? itemViewSize.width : baseViewSize!.width let w: CGFloat = nil == baseSize ? itemSize.width : baseSize!.width
UIView.animateWithDuration(Double(i) * duration, UIView.animateWithDuration(Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [weak self] in
view.alpha = 0 if let s: Menu = self {
view.frame.origin.x = self.origin.x + w view.alpha = 0
animations?(view) view.frame.origin.x = s.origin.x + w
}) { [unowned self] _ in animations?(view)
view.hidden = true }
completion?(view) }) { [weak self] _ in
self.enable(view) if let s: Menu = self {
view.hidden = true
completion?(view)
s.enable(view)
}
} }
} }
opened = false opened = false
...@@ -449,7 +481,7 @@ public class Menu { ...@@ -449,7 +481,7 @@ public class Menu {
/// Layout the views. /// Layout the views.
private func layoutButtons() { private func layoutButtons() {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
let size: CGSize = nil == baseViewSize ? itemViewSize : baseViewSize! let size: CGSize = nil == baseSize ? itemSize : baseSize!
for i in 0..<v.count { for i in 0..<v.count {
let view: UIView = v[i] let view: UIView = v[i]
if 0 == i { if 0 == i {
...@@ -459,9 +491,9 @@ public class Menu { ...@@ -459,9 +491,9 @@ public class Menu {
} else { } else {
view.alpha = 0 view.alpha = 0
view.hidden = true view.hidden = true
view.frame.size = itemViewSize view.frame.size = itemSize
view.frame.origin.x = origin.x + (size.width - itemViewSize.width) / 2 view.frame.origin.x = origin.x + (size.width - itemSize.width) / 2
view.frame.origin.y = origin.y + (size.height - itemViewSize.height) / 2 view.frame.origin.y = origin.y + (size.height - itemSize.height) / 2
view.layer.zPosition = CGFloat(10000 - v.count - i) view.layer.zPosition = CGFloat(10000 - v.count - i)
} }
} }
......
...@@ -32,15 +32,15 @@ import UIKit ...@@ -32,15 +32,15 @@ import UIKit
public extension UIViewController { public extension UIViewController {
/** /**
A convenience property that provides access to the MenuViewController. A convenience property that provides access to the MenuController.
This is the recommended method of accessing the MenuViewController This is the recommended method of accessing the MenuController
through child UIViewControllers. through child UIViewControllers.
*/ */
public var menuViewController: MenuViewController? { public var menuViewController: MenuController? {
var viewController: UIViewController? = self var viewController: UIViewController? = self
while nil != viewController { while nil != viewController {
if viewController is MenuViewController { if viewController is MenuController {
return viewController as? MenuViewController return viewController as? MenuController
} }
viewController = viewController?.parentViewController viewController = viewController?.parentViewController
} }
...@@ -49,7 +49,7 @@ public extension UIViewController { ...@@ -49,7 +49,7 @@ public extension UIViewController {
} }
@IBDesignable @IBDesignable
public class MenuViewController : UIViewController { public class MenuController : UIViewController {
/// Reference to the MenuView. /// Reference to the MenuView.
public private(set) lazy var menuView: MenuView = MenuView() public private(set) lazy var menuView: MenuView = MenuView()
...@@ -133,14 +133,16 @@ public class MenuViewController : UIViewController { ...@@ -133,14 +133,16 @@ public class MenuViewController : UIViewController {
duration: duration, duration: duration,
options: options, options: options,
animations: animations, animations: animations,
completion: { [unowned self] (result: Bool) in completion: { [weak self] (result: Bool) in
toViewController.didMoveToParentViewController(self) if let s: MenuController = self {
self.rootViewController.removeFromParentViewController() toViewController.didMoveToParentViewController(s)
self.rootViewController = toViewController s.rootViewController.removeFromParentViewController()
self.rootViewController.view.clipsToBounds = true s.rootViewController = toViewController
self.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] s.rootViewController.view.clipsToBounds = true
self.view.sendSubviewToBack(self.rootViewController.view) s.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
completion?(result) s.view.sendSubviewToBack(s.rootViewController.view)
completion?(result)
}
}) })
} }
...@@ -201,7 +203,7 @@ public class MenuViewController : UIViewController { ...@@ -201,7 +203,7 @@ public class MenuViewController : UIViewController {
/** /**
A method that adds the passed in controller as a child of A method that adds the passed in controller as a child of
the MenuViewController within the passed in the MenuController within the passed in
container view. container view.
- Parameter viewController: A UIViewController to add as a child. - Parameter viewController: A UIViewController to add as a child.
- Parameter container: A UIView that is the parent of the - Parameter container: A UIView that is the parent of the
......
...@@ -452,14 +452,16 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -452,14 +452,16 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
duration: duration, duration: duration,
options: options, options: options,
animations: animations, animations: animations,
completion: { [unowned self] (result: Bool) in completion: { [weak self] (result: Bool) in
toViewController.didMoveToParentViewController(self) if let s: SideNavigationController = self {
self.rootViewController.removeFromParentViewController() toViewController.didMoveToParentViewController(s)
self.rootViewController = toViewController s.rootViewController.removeFromParentViewController()
self.rootViewController.view.clipsToBounds = true s.rootViewController = toViewController
self.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] s.rootViewController.view.clipsToBounds = true
self.view.sendSubviewToBack(self.rootViewController.view) s.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
completion?(result) s.view.sendSubviewToBack(s.rootViewController.view)
completion?(result)
}
}) })
} }
...@@ -488,25 +490,33 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -488,25 +490,33 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
if hide { if hide {
UIView.animateWithDuration(duration, UIView.animateWithDuration(duration,
animations: { [unowned self] in animations: { [weak self] in
v.bounds.size.width = width if let s: SideNavigationController = self {
v.position.x = -width / 2 v.bounds.size.width = width
self.rootViewController.view.alpha = 1 v.position.x = -width / 2
}) { [unowned self] _ in s.rootViewController.view.alpha = 1
v.shadowPathAutoSizeEnabled = true }
self.layoutSubviews() }) { [weak self] _ in
self.hideView(v) if let s: SideNavigationController = self {
v.shadowPathAutoSizeEnabled = true
s.layoutSubviews()
s.hideView(v)
}
} }
} else { } else {
UIView.animateWithDuration(duration, UIView.animateWithDuration(duration,
animations: { [unowned self] in animations: { [weak self] in
v.bounds.size.width = width if let s: SideNavigationController = self {
v.position.x = width / 2 v.bounds.size.width = width
self.rootViewController.view.alpha = 0.5 v.position.x = width / 2
}) { [unowned self] _ in s.rootViewController.view.alpha = 0.5
v.shadowPathAutoSizeEnabled = true }
self.layoutSubviews() }) { [weak self] _ in
self.showView(v) if let s: SideNavigationController = self {
v.shadowPathAutoSizeEnabled = true
s.layoutSubviews()
s.showView(v)
}
} }
} }
} else { } else {
...@@ -554,25 +564,33 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -554,25 +564,33 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
if hide { if hide {
UIView.animateWithDuration(duration, UIView.animateWithDuration(duration,
animations: { [unowned self] in animations: { [weak self] in
v.bounds.size.width = width if let s: SideNavigationController = self {
v.position.x = self.view.bounds.width + width / 2 v.bounds.size.width = width
self.rootViewController.view.alpha = 1 v.position.x = s.view.bounds.width + width / 2
}) { [unowned self] _ in s.rootViewController.view.alpha = 1
v.shadowPathAutoSizeEnabled = true }
self.layoutSubviews() }) { [weak self] _ in
self.hideView(v) if let s: SideNavigationController = self {
v.shadowPathAutoSizeEnabled = true
s.layoutSubviews()
s.hideView(v)
}
} }
} else { } else {
UIView.animateWithDuration(duration, UIView.animateWithDuration(duration,
animations: { [unowned self] in animations: { [weak self] in
v.bounds.size.width = width if let s: SideNavigationController = self {
v.position.x = self.view.bounds.width - width / 2 v.bounds.size.width = width
self.rootViewController.view.alpha = 0.5 v.position.x = s.view.bounds.width - width / 2
}) { [unowned self] _ in s.rootViewController.view.alpha = 0.5
v.shadowPathAutoSizeEnabled = true }
self.layoutSubviews() }) { [weak self] _ in
self.showView(v) if let s: SideNavigationController = self {
v.shadowPathAutoSizeEnabled = true
s.layoutSubviews()
s.showView(v)
}
} }
} }
} else { } else {
...@@ -633,8 +651,10 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -633,8 +651,10 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
animations: { animations: {
v.position.x = v.width / 2 v.position.x = v.width / 2
self.rootViewController.view.alpha = 0.5 self.rootViewController.view.alpha = 0.5
}) { [unowned self] _ in }) { [weak self] _ in
self.delegate?.sideNavigationDidOpen?(self, position: .Left) if let s: SideNavigationController = self {
s.delegate?.sideNavigationDidOpen?(s, position: .Left)
}
} }
} }
} }
...@@ -654,11 +674,15 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -654,11 +674,15 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
userInteractionEnabled = false userInteractionEnabled = false
delegate?.sideNavigationWillOpen?(self, position: .Right) delegate?.sideNavigationWillOpen?(self, position: .Right)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [unowned self] in animations: { [weak self] in
v.position.x = self.view.bounds.width - v.width / 2 if let s: SideNavigationController = self {
self.rootViewController.view.alpha = 0.5 v.position.x = s.view.bounds.width - v.width / 2
}) { [unowned self] _ in s.rootViewController.view.alpha = 0.5
self.delegate?.sideNavigationDidOpen?(self, position: .Right) }
}) { [weak self] _ in
if let s: SideNavigationController = self {
s.delegate?.sideNavigationDidOpen?(s, position: .Right)
}
} }
} }
} }
...@@ -676,13 +700,17 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -676,13 +700,17 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
userInteractionEnabled = true userInteractionEnabled = true
delegate?.sideNavigationWillClose?(self, position: .Left) delegate?.sideNavigationWillClose?(self, position: .Left)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [unowned self] in animations: { [weak self] in
v.position.x = -v.width / 2 if let s: SideNavigationController = self {
self.rootViewController.view.alpha = 1 v.position.x = -v.width / 2
}) { [unowned self] _ in s.rootViewController.view.alpha = 1
self.hideView(v) }
self.toggleStatusBar() }) { [weak self] _ in
self.delegate?.sideNavigationDidClose?(self, position: .Left) if let s: SideNavigationController = self {
s.hideView(v)
s.toggleStatusBar()
s.delegate?.sideNavigationDidClose?(s, position: .Left)
}
} }
} }
} }
...@@ -701,13 +729,17 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -701,13 +729,17 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
userInteractionEnabled = true userInteractionEnabled = true
delegate?.sideNavigationWillClose?(self, position: .Right) delegate?.sideNavigationWillClose?(self, position: .Right)
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [unowned self] in animations: { [weak self] in
v.position.x = self.view.bounds.width + v.width / 2 if let s: SideNavigationController = self {
self.rootViewController.view.alpha = 1 v.position.x = s.view.bounds.width + v.width / 2
}) { [unowned self] _ in s.rootViewController.view.alpha = 1
self.hideView(v) }
self.toggleStatusBar() }) { [weak self] _ in
self.delegate?.sideNavigationDidClose?(self, position: .Right) if let s: SideNavigationController = self {
s.hideView(v)
s.toggleStatusBar()
s.delegate?.sideNavigationDidClose?(s, position: .Right)
}
} }
} }
} }
......
...@@ -91,9 +91,11 @@ public class TabBar : MaterialView { ...@@ -91,9 +91,11 @@ public class TabBar : MaterialView {
/// Handles the button touch event. /// Handles the button touch event.
internal func handleButton(button: UIButton) { internal func handleButton(button: UIButton) {
UIView.animateWithDuration(0.25, animations: { [unowned self] in UIView.animateWithDuration(0.25, animations: { [weak self] in
self.line.frame.origin.x = button.frame.origin.x if let s: TabBar = self {
self.line.frame.size.width = button.frame.size.width s.line.frame.origin.x = button.frame.origin.x
s.line.frame.size.width = button.frame.size.width
}
}) })
} }
......
...@@ -116,11 +116,15 @@ public class Text : NSObject { ...@@ -116,11 +116,15 @@ public class Text : NSObject {
/// Prepares the pre and post processing callbacks. /// Prepares the pre and post processing callbacks.
private func prepareTextStorageProcessingCallbacks() { private func prepareTextStorageProcessingCallbacks() {
textStorage.textWillProcessEdit = { [unowned self] (textStorage: TextStorage, string: String, range: NSRange) -> Void in textStorage.textWillProcessEdit = { [weak self] (textStorage: TextStorage, string: String, range: NSRange) -> Void in
self.delegate?.textWillProcessEdit?(self, textStorage: textStorage, string: string, range: range) if let s: Text = self {
s.delegate?.textWillProcessEdit?(s, textStorage: textStorage, string: string, range: range)
}
} }
textStorage.textDidProcessEdit = { [unowned self] (textStorage: TextStorage, result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in textStorage.textDidProcessEdit = { [weak self] (textStorage: TextStorage, result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
self.delegate?.textDidProcessEdit?(self, textStorage: textStorage, string: textStorage.string, result: result, flags: flags, stop: stop) if let s: Text = self {
s.delegate?.textDidProcessEdit?(s, textStorage: textStorage, string: textStorage.string, result: result, flags: flags, stop: stop)
}
} }
} }
} }
\ No newline at end of file
...@@ -512,9 +512,11 @@ public class TextView: UITextView { ...@@ -512,9 +512,11 @@ public class TextView: UITextView {
let h: CGFloat = ceil(v.font.lineHeight) let h: CGFloat = ceil(v.font.lineHeight)
v.frame = CGRectMake(0, -h, bounds.width, h) v.frame = CGRectMake(0, -h, bounds.width, h)
v.hidden = false v.hidden = false
UIView.animateWithDuration(0.25, animations: { [unowned self] in UIView.animateWithDuration(0.25, animations: { [weak self] in
v.alpha = 1 if let s: TextView = self {
v.frame.origin.y = -v.frame.height - self.titleLabelAnimationDistance v.alpha = 1
v.frame.origin.y = -v.frame.height - s.titleLabelAnimationDistance
}
}) })
} }
} }
......
...@@ -77,7 +77,6 @@ public class Toolbar : BarView { ...@@ -77,7 +77,6 @@ public class Toolbar : BarView {
/// Basic initializer. /// Basic initializer.
public override init() { public override init() {
super.init() super.init()
print("Toolbar", intrinsicContentSize())
} }
/** /**
......
...@@ -86,19 +86,25 @@ public class ToolbarController : BarViewController { ...@@ -86,19 +86,25 @@ public class ToolbarController : BarViewController {
delegate?.toolbarControllerWillCloseFloatingViewController?(self) delegate?.toolbarControllerWillCloseFloatingViewController?(self)
internalFloatingViewController = nil internalFloatingViewController = nil
UIView.animateWithDuration(0.5, UIView.animateWithDuration(0.5,
animations: { [unowned self] in animations: { [weak self] in
v.view.center.y = 2 * self.view.bounds.height if let s: ToolbarController = self {
self.toolbar.alpha = 1 v.view.center.y = 2 * s.view.bounds.height
self.rootViewController.view.alpha = 1 s.toolbar.alpha = 1
}) { [unowned self] _ in s.rootViewController.view.alpha = 1
v.willMoveToParentViewController(nil) }
v.view.removeFromSuperview() }) { [weak self] _ in
v.removeFromParentViewController() if let s: ToolbarController = self {
v.view.layer.shouldRasterize = false v.willMoveToParentViewController(nil)
self.userInteractionEnabled = true v.view.removeFromSuperview()
self.toolbar.userInteractionEnabled = true v.removeFromParentViewController()
dispatch_async(dispatch_get_main_queue()) { [unowned self] in v.view.layer.shouldRasterize = false
self.delegate?.toolbarControllerDidCloseFloatingViewController?(self) s.userInteractionEnabled = true
s.toolbar.userInteractionEnabled = true
dispatch_async(dispatch_get_main_queue()) { [weak self] in
if let s: ToolbarController = self {
s.delegate?.toolbarControllerDidCloseFloatingViewController?(s)
}
}
} }
} }
} }
...@@ -124,15 +130,21 @@ public class ToolbarController : BarViewController { ...@@ -124,15 +130,21 @@ public class ToolbarController : BarViewController {
toolbar.userInteractionEnabled = false toolbar.userInteractionEnabled = false
delegate?.toolbarControllerWillOpenFloatingViewController?(self) delegate?.toolbarControllerWillOpenFloatingViewController?(self)
UIView.animateWithDuration(0.5, UIView.animateWithDuration(0.5,
animations: { [unowned self] in animations: { [weak self] in
v.view.center.y = self.view.bounds.height / 2 if let s: ToolbarController = self {
self.toolbar.alpha = 0.5 v.view.center.y = s.view.bounds.height / 2
self.rootViewController.view.alpha = 0.5 s.toolbar.alpha = 0.5
}) { [unowned self] _ in s.rootViewController.view.alpha = 0.5
v.view.layer.shouldRasterize = false }
self.view.layer.shouldRasterize = false }) { [weak self] _ in
dispatch_async(dispatch_get_main_queue()) { [unowned self] in if let s: ToolbarController = self {
self.delegate?.toolbarControllerDidOpenFloatingViewController?(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)
}
}
} }
} }
} }
......
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