Commit 30d06aeb by Daniel Dahan

updated MenuView to handle outside touch events

parent d7669534
...@@ -162,7 +162,7 @@ class ViewController: UIViewController { ...@@ -162,7 +162,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.baseSize = CGSizeMake(diameter, diameter) fabMenu.baseViewSize = CGSizeMake(diameter, diameter)
fabMenu.views = [btn1, btn2, btn3, btn4] fabMenu.views = [btn1, btn2, btn3, btn4]
} }
...@@ -204,7 +204,7 @@ class ViewController: UIViewController { ...@@ -204,7 +204,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.buttonSize = CGSizeMake(120, height) flatMenu.itemViewSize = CGSizeMake(120, height)
flatMenu.views = [btn1, btn2, btn3, btn4] flatMenu.views = [btn1, btn2, btn3, btn4]
} }
...@@ -238,7 +238,7 @@ class ViewController: UIViewController { ...@@ -238,7 +238,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.buttonSize = btn1.intrinsicContentSize() flashMenu.itemViewSize = btn1.intrinsicContentSize()
flashMenu.views = [btn1, btn2, btn3] flashMenu.views = [btn1, btn2, btn3]
} }
} }
......
...@@ -83,6 +83,11 @@ class ViewController: UIViewController { ...@@ -83,6 +83,11 @@ class ViewController: UIViewController {
first?.setImage(image, forState: .Highlighted) first?.setImage(image, forState: .Highlighted)
} }
/// Handle the menuView touch event.
internal func handleButton(button: UIButton) {
print("Hit Button \(button)")
}
/// General preparation statements are placed here. /// General preparation statements are placed here.
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
...@@ -120,6 +125,7 @@ class ViewController: UIViewController { ...@@ -120,6 +125,7 @@ class ViewController: UIViewController {
btn2.borderWidth = 1 btn2.borderWidth = 1
btn2.setImage(image, forState: .Normal) btn2.setImage(image, forState: .Normal)
btn2.setImage(image, forState: .Highlighted) btn2.setImage(image, forState: .Highlighted)
btn2.addTarget(self, action: "handleButton:", forControlEvents: .TouchUpInside)
menuView.addSubview(btn2) menuView.addSubview(btn2)
image = UIImage(named: "ic_photo_camera_white")?.imageWithRenderingMode(.AlwaysTemplate) image = UIImage(named: "ic_photo_camera_white")?.imageWithRenderingMode(.AlwaysTemplate)
...@@ -132,6 +138,7 @@ class ViewController: UIViewController { ...@@ -132,6 +138,7 @@ class ViewController: UIViewController {
btn3.borderWidth = 1 btn3.borderWidth = 1
btn3.setImage(image, forState: .Normal) btn3.setImage(image, forState: .Normal)
btn3.setImage(image, forState: .Highlighted) btn3.setImage(image, forState: .Highlighted)
btn3.addTarget(self, action: "handleButton:", forControlEvents: .TouchUpInside)
menuView.addSubview(btn3) menuView.addSubview(btn3)
image = UIImage(named: "ic_note_add_white")?.imageWithRenderingMode(.AlwaysTemplate) image = UIImage(named: "ic_note_add_white")?.imageWithRenderingMode(.AlwaysTemplate)
...@@ -144,11 +151,12 @@ class ViewController: UIViewController { ...@@ -144,11 +151,12 @@ class ViewController: UIViewController {
btn4.borderWidth = 1 btn4.borderWidth = 1
btn4.setImage(image, forState: .Normal) btn4.setImage(image, forState: .Normal)
btn4.setImage(image, forState: .Highlighted) btn4.setImage(image, forState: .Highlighted)
btn4.addTarget(self, action: "handleButton:", forControlEvents: .TouchUpInside)
menuView.addSubview(btn4) menuView.addSubview(btn4)
// 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.baseSize = CGSizeMake(diameter, diameter) menuView.menu.baseViewSize = CGSizeMake(diameter, diameter)
menuView.menu.views = [btn1, btn2, btn3, btn4] menuView.menu.views = [btn1, btn2, btn3, btn4]
view.addSubview(menuView) view.addSubview(menuView)
......
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '1.32.1' s.version = '1.32.2'
s.license = 'BSD' s.license = 'BSD'
s.summary = 'Express your creativity with Material, an animation and graphics framework for Google\'s Material Design and Apple\'s Flat UI in Swift.' s.summary = 'Express your creativity with Material, an animation and graphics framework for Google\'s Material Design and Apple\'s Flat UI in Swift.'
s.homepage = 'http://cosmicmind.io' s.homepage = 'http://cosmicmind.io'
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.32.1</string> <string>1.32.2</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -72,11 +72,11 @@ public class Menu { ...@@ -72,11 +72,11 @@ public class Menu {
} }
} }
/// Size of views, not including the first button. /// Size of views, not including the first view.
public var buttonSize: CGSize = CGSizeMake(48, 48) public var itemViewSize: CGSize = CGSizeMake(48, 48)
/// An Optional base button size. /// An Optional base view size.
public var baseSize: CGSize? public var baseViewSize: CGSize?
/** /**
Initializer. Initializer.
...@@ -88,7 +88,7 @@ public class Menu { ...@@ -88,7 +88,7 @@ public class Menu {
self.spacing = spacing self.spacing = spacing
} }
/// Reload the button layout. /// Reload the view layout.
public func reloadLayout() { public func reloadLayout() {
opened = false opened = false
layoutButtons() layoutButtons()
...@@ -96,13 +96,13 @@ public class Menu { ...@@ -96,13 +96,13 @@ public class Menu {
/** /**
Open the Menu component with animation options. Open the Menu component with animation options.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
public func open(duration duration: NSTimeInterval = 0.15, delay: NSTimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) { public func open(duration duration: NSTimeInterval = 0.15, delay: NSTimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) {
if enabled { if enabled {
...@@ -122,13 +122,13 @@ public class Menu { ...@@ -122,13 +122,13 @@ public class Menu {
/** /**
Close the Menu component with animation options. Close the Menu component with animation options.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
public func close(duration duration: NSTimeInterval = 0.15, delay: NSTimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) { public func close(duration duration: NSTimeInterval = 0.15, delay: NSTimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) {
if enabled { if enabled {
...@@ -148,13 +148,13 @@ public class Menu { ...@@ -148,13 +148,13 @@ public class Menu {
/** /**
Open the Menu component with animation options in the Up direction. Open the Menu component with animation options in the Up direction.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
private func openUpAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { private func openUpAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
...@@ -163,8 +163,8 @@ public class Menu { ...@@ -163,8 +163,8 @@ public class Menu {
if nil == base { if nil == base {
base = v[0] base = v[0]
} }
let button: UIView = v[i] let view: UIView = v[i]
button.hidden = false view.hidden = false
UIView.animateWithDuration(Double(i) * duration, UIView.animateWithDuration(Double(i) * duration,
delay: delay, delay: delay,
...@@ -172,12 +172,12 @@ public class Menu { ...@@ -172,12 +172,12 @@ public class Menu {
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [unowned self] in
button.alpha = 1 view.alpha = 1
button.frame.origin.y = base!.frame.origin.y - CGFloat(i) * self.buttonSize.height - CGFloat(i) * self.spacing view.frame.origin.y = base!.frame.origin.y - CGFloat(i) * self.itemViewSize.height - CGFloat(i) * self.spacing
animations?(button) animations?(view)
}, completion: { [unowned self] _ in }, completion: { [unowned self] _ in
completion?(button) completion?(view)
self.enable(button) self.enable(view)
}) })
} }
opened = true opened = true
...@@ -186,18 +186,18 @@ public class Menu { ...@@ -186,18 +186,18 @@ public class Menu {
/** /**
Close the Menu component with animation options in the Up direction. Close the Menu component with animation options in the Up direction.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
public func closeUpAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { public func closeUpAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
let button: UIView = v[i] let view: UIView = v[i]
UIView.animateWithDuration(Double(i) * duration, UIView.animateWithDuration(Double(i) * duration,
delay: delay, delay: delay,
...@@ -205,13 +205,13 @@ public class Menu { ...@@ -205,13 +205,13 @@ public class Menu {
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [unowned self] in
button.alpha = 0 view.alpha = 0
button.frame.origin.y = self.origin.y view.frame.origin.y = self.origin.y
animations?(button) animations?(view)
}, completion: { [unowned self] _ in }, completion: { [unowned self] _ in
button.hidden = true view.hidden = true
completion?(button) completion?(view)
self.enable(button) self.enable(view)
}) })
} }
opened = false opened = false
...@@ -220,13 +220,13 @@ public class Menu { ...@@ -220,13 +220,13 @@ public class Menu {
/** /**
Open the Menu component with animation options in the Down direction. Open the Menu component with animation options in the Down direction.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
private func openDownAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { private func openDownAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
...@@ -236,22 +236,22 @@ public class Menu { ...@@ -236,22 +236,22 @@ public class Menu {
base = v[0] base = v[0]
} }
let button: UIView = v[i] let view: UIView = v[i]
button.hidden = false view.hidden = false
let h: CGFloat = nil == baseSize ? buttonSize.height : baseSize!.height let h: CGFloat = nil == baseViewSize ? itemViewSize.height : baseViewSize!.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: { [unowned self] in
button.alpha = 1 view.alpha = 1
button.frame.origin.y = base!.frame.origin.y + h + CGFloat(i - 1) * self.buttonSize.height + CGFloat(i) * self.spacing view.frame.origin.y = base!.frame.origin.y + h + CGFloat(i - 1) * self.itemViewSize.height + CGFloat(i) * self.spacing
animations?(button) animations?(view)
}, completion: { [unowned self] _ in }, completion: { [unowned self] _ in
completion?(button) completion?(view)
self.enable(button) self.enable(view)
}) })
} }
opened = true opened = true
...@@ -260,33 +260,33 @@ public class Menu { ...@@ -260,33 +260,33 @@ public class Menu {
/** /**
Close the Menu component with animation options in the Down direction. Close the Menu component with animation options in the Down direction.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
public func closeDownAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { public func closeDownAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
let button: UIView = v[i] let view: UIView = v[i]
let h: CGFloat = nil == baseSize ? buttonSize.height : baseSize!.height let h: CGFloat = nil == baseViewSize ? itemViewSize.height : baseViewSize!.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: { [unowned self] in
button.alpha = 0 view.alpha = 0
button.frame.origin.y = self.origin.y + h view.frame.origin.y = self.origin.y + h
animations?(button) animations?(view)
}, completion: { [unowned self] _ in }, completion: { [unowned self] _ in
button.hidden = true view.hidden = true
completion?(button) completion?(view)
self.enable(button) self.enable(view)
}) })
} }
opened = false opened = false
...@@ -295,13 +295,13 @@ public class Menu { ...@@ -295,13 +295,13 @@ public class Menu {
/** /**
Open the Menu component with animation options in the Left direction. Open the Menu component with animation options in the Left direction.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
private func openLeftAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { private func openLeftAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
...@@ -311,8 +311,8 @@ public class Menu { ...@@ -311,8 +311,8 @@ public class Menu {
base = v[0] base = v[0]
} }
let button: UIView = v[i] let view: UIView = v[i]
button.hidden = false view.hidden = false
UIView.animateWithDuration(Double(i) * duration, UIView.animateWithDuration(Double(i) * duration,
delay: delay, delay: delay,
...@@ -320,12 +320,12 @@ public class Menu { ...@@ -320,12 +320,12 @@ public class Menu {
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [unowned self] in animations: { [unowned self] in
button.alpha = 1 view.alpha = 1
button.frame.origin.x = base!.frame.origin.x - CGFloat(i) * self.buttonSize.width - CGFloat(i) * self.spacing view.frame.origin.x = base!.frame.origin.x - CGFloat(i) * self.itemViewSize.width - CGFloat(i) * self.spacing
animations?(button) animations?(view)
}, completion: { [unowned self] _ in }, completion: { [unowned self] _ in
completion?(button) completion?(view)
self.enable(button) self.enable(view)
}) })
} }
opened = true opened = true
...@@ -334,31 +334,31 @@ public class Menu { ...@@ -334,31 +334,31 @@ public class Menu {
/** /**
Close the Menu component with animation options in the Left direction. Close the Menu component with animation options in the Left direction.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
public func closeLeftAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { public func closeLeftAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
let button: UIView = v[i] let view: UIView = v[i]
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: { [unowned self] in
button.alpha = 0 view.alpha = 0
button.frame.origin.x = self.origin.x view.frame.origin.x = self.origin.x
animations?(button) animations?(view)
}, completion: { [unowned self] _ in }, completion: { [unowned self] _ in
button.hidden = true view.hidden = true
completion?(button) completion?(view)
self.enable(button) self.enable(view)
}) })
} }
opened = false opened = false
...@@ -367,13 +367,13 @@ public class Menu { ...@@ -367,13 +367,13 @@ public class Menu {
/** /**
Open the Menu component with animation options in the Right direction. Open the Menu component with animation options in the Right direction.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
private func openRightAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { private func openRightAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
...@@ -382,22 +382,22 @@ public class Menu { ...@@ -382,22 +382,22 @@ public class Menu {
if nil == base { if nil == base {
base = v[0] base = v[0]
} }
let button: UIView = v[i] let view: UIView = v[i]
button.hidden = false view.hidden = false
let h: CGFloat = nil == baseSize ? buttonSize.height : baseSize!.height let h: CGFloat = nil == baseViewSize ? itemViewSize.height : baseViewSize!.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: { [unowned self] in
button.alpha = 1 view.alpha = 1
button.frame.origin.x = base!.frame.origin.x + h + CGFloat(i - 1) * self.buttonSize.width + CGFloat(i) * self.spacing view.frame.origin.x = base!.frame.origin.x + h + CGFloat(i - 1) * self.itemViewSize.width + CGFloat(i) * self.spacing
animations?(button) animations?(view)
}, completion: { [unowned self] _ in }, completion: { [unowned self] _ in
completion?(button) completion?(view)
self.enable(button) self.enable(view)
}) })
} }
opened = true opened = true
...@@ -406,33 +406,33 @@ public class Menu { ...@@ -406,33 +406,33 @@ public class Menu {
/** /**
Close the Menu component with animation options in the Right direction. Close the Menu component with animation options in the Right direction.
- Parameter duration: The time for each button's animation. - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each button's animation. - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each button's animation. - Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each button's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
public func closeRightAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { public func closeRightAnimation(duration: NSTimeInterval, delay: NSTimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
for var i: Int = 1, l: Int = v.count; i < l; ++i { for var i: Int = 1, l: Int = v.count; i < l; ++i {
let button: UIView = v[i] let view: UIView = v[i]
let w: CGFloat = nil == baseSize ? buttonSize.width : baseSize!.width let w: CGFloat = nil == baseViewSize ? itemViewSize.width : baseViewSize!.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: { [unowned self] in
button.alpha = 0 view.alpha = 0
button.frame.origin.x = self.origin.x + w view.frame.origin.x = self.origin.x + w
animations?(button) animations?(view)
}, completion: { [unowned self] _ in }, completion: { [unowned self] _ in
button.hidden = true view.hidden = true
completion?(button) completion?(view)
self.enable(button) self.enable(view)
}) })
} }
opened = false opened = false
...@@ -442,20 +442,20 @@ public class Menu { ...@@ -442,20 +442,20 @@ 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 == baseSize ? buttonSize : baseSize! let size: CGSize = nil == baseViewSize ? itemViewSize : baseViewSize!
for var i: Int = 0, l: Int = v.count; i < l; ++i { for var i: Int = 0, l: Int = v.count; i < l; ++i {
let button: UIView = v[i] let view: UIView = v[i]
if 0 == i { if 0 == i {
button.frame.size = size view.frame.size = size
button.frame.origin = origin view.frame.origin = origin
button.layer.zPosition = 10000 view.layer.zPosition = 10000
} else { } else {
button.alpha = 0 view.alpha = 0
button.hidden = true view.hidden = true
button.frame.size = buttonSize view.frame.size = itemViewSize
button.frame.origin.x = origin.x + (size.width - buttonSize.width) / 2 view.frame.origin.x = origin.x + (size.width - itemViewSize.width) / 2
button.frame.origin.y = origin.y + (size.height - buttonSize.height) / 2 view.frame.origin.y = origin.y + (size.height - itemViewSize.height) / 2
button.layer.zPosition = CGFloat(10000 - v.count - i) view.layer.zPosition = CGFloat(10000 - v.count - i)
} }
} }
} }
...@@ -471,12 +471,12 @@ public class Menu { ...@@ -471,12 +471,12 @@ public class Menu {
} }
/** /**
Enable the Menu if the last button is equal to the passed in button. Enable the Menu if the last view is equal to the passed in view.
- Parameter button: UIView that is passed in to compare. - Parameter view: UIView that is passed in to compare.
*/ */
private func enable(button: UIView) { private func enable(view: UIView) {
if let v: Array<UIView> = views { if let v: Array<UIView> = views {
if button == v.last { if view == v.last {
enabled = true enabled = true
} }
} }
......
...@@ -45,5 +45,20 @@ public class MenuView : MaterialPulseView { ...@@ -45,5 +45,20 @@ public class MenuView : MaterialPulseView {
super.prepareView() super.prepareView()
pulseColor = nil pulseColor = nil
pulseScale = false pulseScale = false
clipsToBounds = false
}
public override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
/**
Since the subviews will be outside the bounds of this view,
we need to look at the subviews to see if we have a hit.
*/
for v in subviews {
let p: CGPoint = v.convertPoint(point, fromView: self)
if CGRectContainsPoint(v.bounds, p) {
return v.hitTest(p, withEvent: event)
}
}
return super.hitTest(point, withEvent: event)
} }
} }
\ No newline at end of file
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