Commit f5619913 by Daniel Dahan

updated references from unowned to weak

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