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>
......
...@@ -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