Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
952aa351
Commit
952aa351
authored
May 28, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated PR for closeMenu when tapping in outside space
parent
800708dd
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
46 deletions
+93
-46
Examples/Programmatic/App/App/AppDelegate.swift
+3
-3
Examples/Programmatic/App/App/RecipesViewController.swift
+2
-2
Examples/Programmatic/MenuController/MenuController.xcodeproj/project.pbxproj
+10
-4
Examples/Programmatic/MenuController/MenuController/AppMenuController.swift
+30
-13
Sources/iOS/Menu.swift
+38
-17
Sources/iOS/MenuController.swift
+1
-1
Sources/iOS/MenuView.swift
+9
-6
No files found.
Examples/Programmatic/App/App/AppDelegate.swift
View file @
952aa351
...
...
@@ -39,11 +39,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func
application
(
application
:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions
:
[
NSObject
:
AnyObject
]?)
->
Bool
{
let
navigationController
:
AppNavigationController
=
AppNavigationController
(
rootViewController
:
RecipesViewController
())
let
menu
View
Controller
:
AppMenuController
=
AppMenuController
(
rootViewController
:
navigationController
)
menu
View
Controller
.
edgesForExtendedLayout
=
.
None
let
menuController
:
AppMenuController
=
AppMenuController
(
rootViewController
:
navigationController
)
menuController
.
edgesForExtendedLayout
=
.
None
let
bottomNavigationController
:
BottomNavigationController
=
BottomNavigationController
()
bottomNavigationController
.
viewControllers
=
[
menu
View
Controller
,
VideoViewController
(),
PhotoViewController
()]
bottomNavigationController
.
viewControllers
=
[
menuController
,
VideoViewController
(),
PhotoViewController
()]
bottomNavigationController
.
selectedIndex
=
0
bottomNavigationController
.
tabBar
.
tintColor
=
MaterialColor
.
white
bottomNavigationController
.
tabBar
.
backgroundColor
=
MaterialColor
.
grey
.
darken4
...
...
Examples/Programmatic/App/App/RecipesViewController.swift
View file @
952aa351
...
...
@@ -76,7 +76,7 @@ class RecipesViewController: UIViewController {
override
func
viewDidAppear
(
animated
:
Bool
)
{
super
.
viewDidAppear
(
animated
)
// Show the menuView.
menu
View
Controller
?
.
menuView
.
animate
(
MaterialAnimation
.
animationGroup
([
menuController
?
.
menuView
.
animate
(
MaterialAnimation
.
animationGroup
([
MaterialAnimation
.
rotate
(
rotation
:
3
),
MaterialAnimation
.
translateY
(
0
)
]))
...
...
@@ -87,7 +87,7 @@ class RecipesViewController: UIViewController {
// Disable the SideNavigation.
// Hide the menuView.
menu
View
Controller
?
.
menuView
.
animate
(
MaterialAnimation
.
animationGroup
([
menuController
?
.
menuView
.
animate
(
MaterialAnimation
.
animationGroup
([
MaterialAnimation
.
rotate
(
rotation
:
3
),
MaterialAnimation
.
translateY
(
150
)
]))
...
...
Examples/Programmatic/MenuController/MenuController.xcodeproj/project.pbxproj
View file @
952aa351
...
...
@@ -10,10 +10,12 @@
966ECF521CF6162F00BB0BDF
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966ECF511CF6162F00BB0BDF
/* AppDelegate.swift */
;
};
966ECF591CF6162F00BB0BDF
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966ECF581CF6162F00BB0BDF
/* Assets.xcassets */
;
};
966ECF5C1CF6162F00BB0BDF
/* LaunchScreen.storyboard in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966ECF5A1CF6162F00BB0BDF
/* LaunchScreen.storyboard */
;
};
966ECF6B1CF616F500BB0BDF
/* AppMenu
ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966ECF671CF616F500BB0BDF
/* AppMenuView
Controller.swift */
;
};
966ECF6B1CF616F500BB0BDF
/* AppMenu
Controller.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966ECF671CF616F500BB0BDF
/* AppMenu
Controller.swift */
;
};
966ECF6C1CF616F500BB0BDF
/* BlueViewcontroller.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966ECF681CF616F500BB0BDF
/* BlueViewcontroller.swift */
;
};
966ECF6D1CF616F500BB0BDF
/* GreenViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966ECF691CF616F500BB0BDF
/* GreenViewController.swift */
;
};
966ECF6E1CF616F500BB0BDF
/* YellowViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966ECF6A1CF616F500BB0BDF
/* YellowViewController.swift */
;
};
96FFF57A1CFA52DC001E8048
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96FFF5791CFA52DC001E8048
/* Material.framework */
;
};
96FFF57B1CFA52DC001E8048
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96FFF5791CFA52DC001E8048
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
...
...
@@ -23,6 +25,7 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
96FFF57B1CFA52DC001E8048
/* Material.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -35,10 +38,11 @@
966ECF581CF6162F00BB0BDF
/* Assets.xcassets */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
folder.assetcatalog
;
path
=
Assets.xcassets
;
sourceTree
=
"<group>"
;
};
966ECF5B1CF6162F00BB0BDF
/* Base */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file.storyboard
;
name
=
Base
;
path
=
Base.lproj/LaunchScreen.storyboard
;
sourceTree
=
"<group>"
;
};
966ECF5D1CF6162F00BB0BDF
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
966ECF671CF616F500BB0BDF
/* AppMenu
ViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppMenuView
Controller.swift
;
sourceTree
=
"<group>"
;
};
966ECF671CF616F500BB0BDF
/* AppMenu
Controller.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppMenu
Controller.swift
;
sourceTree
=
"<group>"
;
};
966ECF681CF616F500BB0BDF
/* BlueViewcontroller.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
BlueViewcontroller.swift
;
sourceTree
=
"<group>"
;
};
966ECF691CF616F500BB0BDF
/* GreenViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
GreenViewController.swift
;
sourceTree
=
"<group>"
;
};
966ECF6A1CF616F500BB0BDF
/* YellowViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
YellowViewController.swift
;
sourceTree
=
"<group>"
;
};
96FFF5791CFA52DC001E8048
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
Material.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/CosmicMind-hgvxkqfizbxkrsfcxbtlafgqkbve/Build/Products/Debug-iphoneos/Material.framework"
;
sourceTree
=
"<absolute>"
;
};
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
...
...
@@ -46,6 +50,7 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
96FFF57A1CFA52DC001E8048
/* Material.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -55,6 +60,7 @@
966ECF451CF6162F00BB0BDF
=
{
isa
=
PBXGroup
;
children
=
(
96FFF5791CFA52DC001E8048
/* Material.framework */
,
966ECF501CF6162F00BB0BDF
/* MenuController */
,
966ECF4F1CF6162F00BB0BDF
/* Products */
,
);
...
...
@@ -72,7 +78,7 @@
isa
=
PBXGroup
;
children
=
(
966ECF511CF6162F00BB0BDF
/* AppDelegate.swift */
,
966ECF671CF616F500BB0BDF
/* AppMenu
View
Controller.swift */
,
966ECF671CF616F500BB0BDF
/* AppMenuController.swift */
,
966ECF681CF616F500BB0BDF
/* BlueViewcontroller.swift */
,
966ECF691CF616F500BB0BDF
/* GreenViewController.swift */
,
966ECF6A1CF616F500BB0BDF
/* YellowViewController.swift */
,
...
...
@@ -156,7 +162,7 @@
files
=
(
966ECF521CF6162F00BB0BDF
/* AppDelegate.swift in Sources */
,
966ECF6C1CF616F500BB0BDF
/* BlueViewcontroller.swift in Sources */
,
966ECF6B1CF616F500BB0BDF
/* AppMenu
View
Controller.swift in Sources */
,
966ECF6B1CF616F500BB0BDF
/* AppMenuController.swift in Sources */
,
966ECF6E1CF616F500BB0BDF
/* YellowViewController.swift in Sources */
,
966ECF6D1CF616F500BB0BDF
/* GreenViewController.swift in Sources */
,
);
...
...
Examples/Programmatic/MenuController/MenuController/AppMenu
View
Controller.swift
→
Examples/Programmatic/MenuController/MenuController/AppMenuController.swift
View file @
952aa351
...
...
@@ -36,14 +36,14 @@ flow of your application.
import
UIKit
import
Material
class
AppMenuController
:
MenuController
{
class
AppMenuController
:
MenuController
,
MenuViewDelegate
{
/// MenuView diameter.
private
let
baseSize
:
CGSize
=
CGSizeMake
(
56
,
56
)
/// MenuView inset.
private
let
menuViewInset
:
CGFloat
=
16
/// Loads the BlueViewController into the menu
View
Controllers rootViewController.
/// Loads the BlueViewController into the menuControllers rootViewController.
func
handleBlueButton
()
{
if
rootViewController
is
BlueViewController
{
return
...
...
@@ -54,7 +54,7 @@ class AppMenuController: MenuController {
}
}
/// Loads the GreenViewController into the menu
View
Controllers rootViewController.
/// Loads the GreenViewController into the menuControllers rootViewController.
func
handleGreenButton
()
{
if
rootViewController
is
GreenViewController
{
return
...
...
@@ -65,11 +65,11 @@ class AppMenuController: MenuController {
}
}
/// Loads the YellowViewController into the menu
View
Controllers rootViewController.
/// Loads the YellowViewController into the menuControllers rootViewController.
func
handleYellowButton
()
{
// if (rootViewController as? ToolbarController)?.
rootViewController is YellowViewController {
//
return
//
}
if
rootViewController
is
YellowViewController
{
return
}
closeMenu
{
[
weak
self
]
in
self
?
.
transitionFromRootViewController
(
YellowViewController
(),
options
:
[
.
TransitionCrossDissolve
])
...
...
@@ -79,14 +79,26 @@ class AppMenuController: MenuController {
/// Handle the menuView touch event.
func
handleMenu
()
{
if
menuView
.
menu
.
opened
{
menuViewController
?
.
rootViewController
.
view
.
alpha
=
1
closeMenu
()
}
else
{
menuViewController
?
.
rootViewController
.
view
.
alpha
=
0.5
openMenu
()
}
}
override
func
openMenu
(
completion
:
(()
->
Void
)?
=
nil
)
{
super
.
openMenu
(
completion
)
if
menuView
.
menu
.
opened
{
rootViewController
.
view
.
alpha
=
0.5
}
}
override
func
closeMenu
(
completion
:
(()
->
Void
)?
=
nil
)
{
super
.
closeMenu
(
completion
)
if
!
menuView
.
menu
.
opened
{
rootViewController
.
view
.
alpha
=
1
}
}
/// Prepares view.
override
func
prepareView
()
{
super
.
prepareView
()
...
...
@@ -94,16 +106,20 @@ class AppMenuController: MenuController {
prepareMenuView
()
}
func
menuViewDidTapOutside
(
menuView
:
MenuView
)
{
closeMenu
()
}
/// Prepares the add button.
private
func
prepareMenuView
()
{
var
image
:
UIImage
?
=
UIImage
(
named
:
"ic_add_white"
)
var
image
:
UIImage
?
=
MaterialIcon
.
cm
.
add
let
btn1
:
FabButton
=
FabButton
()
btn1
.
setImage
(
image
,
forState
:
.
Normal
)
btn1
.
setImage
(
image
,
forState
:
.
Highlighted
)
btn1
.
addTarget
(
self
,
action
:
#selector(
handleMenu
)
,
forControlEvents
:
.
TouchUpInside
)
menuView
.
addSubview
(
btn1
)
image
=
UIImage
(
named
:
"ic_create_white"
)
image
=
MaterialIcon
.
cm
.
videocam
let
btn2
:
FabButton
=
FabButton
()
btn2
.
backgroundColor
=
MaterialColor
.
blue
.
base
btn2
.
setImage
(
image
,
forState
:
.
Normal
)
...
...
@@ -111,7 +127,7 @@ class AppMenuController: MenuController {
menuView
.
addSubview
(
btn2
)
btn2
.
addTarget
(
self
,
action
:
#selector(
handleBlueButton
)
,
forControlEvents
:
.
TouchUpInside
)
image
=
UIImage
(
named
:
"ic_photo_camera_white"
)
image
=
MaterialIcon
.
cm
.
photoLibrary
let
btn3
:
FabButton
=
FabButton
()
btn3
.
backgroundColor
=
MaterialColor
.
green
.
base
btn3
.
setImage
(
image
,
forState
:
.
Normal
)
...
...
@@ -119,7 +135,7 @@ class AppMenuController: MenuController {
menuView
.
addSubview
(
btn3
)
btn3
.
addTarget
(
self
,
action
:
#selector(
handleGreenButton
)
,
forControlEvents
:
.
TouchUpInside
)
image
=
UIImage
(
named
:
"ic_note_add_white"
)
image
=
MaterialIcon
.
cm
.
pen
let
btn4
:
FabButton
=
FabButton
()
btn4
.
backgroundColor
=
MaterialColor
.
yellow
.
base
btn4
.
setImage
(
image
,
forState
:
.
Normal
)
...
...
@@ -130,6 +146,7 @@ class AppMenuController: MenuController {
// Initialize the menu and setup the configuration options.
menuView
.
menu
.
baseSize
=
baseSize
menuView
.
menu
.
views
=
[
btn1
,
btn2
,
btn3
,
btn4
]
menuView
.
delegate
=
self
view
.
addSubview
(
menuView
)
MaterialLayout
.
size
(
view
,
child
:
menuView
,
width
:
baseSize
.
width
,
height
:
baseSize
.
height
)
...
...
Sources/iOS/Menu.swift
View file @
952aa351
...
...
@@ -94,6 +94,11 @@ public class Menu {
self
.
origin
=
origin
self
.
spacing
=
spacing
}
/// Convenience initializer.
public
convenience
init
()
{
self
.
init
(
origin
:
CGPointZero
)
}
/// Reload the view layout.
public
func
reloadLayout
()
{
...
...
@@ -186,12 +191,14 @@ public class Menu {
}
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
completion
?(
view
)
s
.
enable
(
view
)
if
view
==
v
.
last
{
s
.
opened
=
true
}
completion
?(
view
)
}
}
}
opened
=
true
}
}
...
...
@@ -224,12 +231,14 @@ public class Menu {
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
view
.
hidden
=
true
completion
?(
view
)
s
.
enable
(
view
)
if
view
==
v
.
last
{
s
.
opened
=
false
}
completion
?(
view
)
}
}
}
opened
=
false
}
}
...
...
@@ -268,12 +277,14 @@ public class Menu {
}
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
completion
?(
view
)
s
.
enable
(
view
)
if
view
==
v
.
last
{
s
.
opened
=
true
}
completion
?(
view
)
}
}
}
opened
=
true
}
}
...
...
@@ -307,12 +318,14 @@ public class Menu {
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
view
.
hidden
=
true
completion
?(
view
)
s
.
enable
(
view
)
if
view
==
v
.
last
{
s
.
opened
=
false
}
completion
?(
view
)
}
}
}
opened
=
false
}
}
...
...
@@ -350,12 +363,14 @@ public class Menu {
}
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
completion
?(
view
)
s
.
enable
(
view
)
if
view
==
v
.
last
{
s
.
opened
=
true
}
completion
?(
view
)
}
}
}
opened
=
true
}
}
...
...
@@ -387,12 +402,14 @@ public class Menu {
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
view
.
hidden
=
true
completion
?(
view
)
s
.
enable
(
view
)
if
view
==
v
.
last
{
s
.
opened
=
false
}
completion
?(
view
)
}
}
}
opened
=
false
}
}
...
...
@@ -430,12 +447,14 @@ public class Menu {
}
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
completion
?(
view
)
s
.
enable
(
view
)
if
view
==
v
.
last
{
s
.
opened
=
true
}
completion
?(
view
)
}
}
}
opened
=
true
}
}
...
...
@@ -453,7 +472,7 @@ public class Menu {
if
let
v
:
Array
<
UIView
>
=
views
{
for
i
in
1
..<
v
.
count
{
let
view
:
UIView
=
v
[
i
]
let
w
:
CGFloat
=
nil
==
baseSize
?
itemSize
.
width
:
baseSize
!.
width
UIView
.
animateWithDuration
(
Double
(
i
)
*
duration
,
delay
:
delay
,
...
...
@@ -469,12 +488,14 @@ public class Menu {
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
view
.
hidden
=
true
completion
?(
view
)
s
.
enable
(
view
)
if
view
==
v
.
last
{
s
.
opened
=
false
}
completion
?(
view
)
}
}
}
opened
=
false
}
}
...
...
Sources/iOS/MenuController.swift
View file @
952aa351
...
...
@@ -36,7 +36,7 @@ public extension UIViewController {
This is the recommended method of accessing the MenuController
through child UIViewControllers.
*/
public
var
menu
View
Controller
:
MenuController
?
{
public
var
menuController
:
MenuController
?
{
var
viewController
:
UIViewController
?
=
self
while
nil
!=
viewController
{
if
viewController
is
MenuController
{
...
...
Sources/iOS/MenuView.swift
View file @
952aa351
...
...
@@ -31,8 +31,7 @@
import
UIKit
@objc(MenuViewDelegate)
public
protocol
MenuViewDelegate
:
MaterialDelegate
{
public
protocol
MenuViewDelegate
:
MaterialDelegate
{
/// Gets called when the user taps outside menu buttons.
optional
func
menuViewDidTapOutside
(
menuView
:
MenuView
)
...
...
@@ -40,7 +39,7 @@ public protocol MenuViewDelegate: MaterialDelegate {
public
class
MenuView
:
MaterialPulseView
{
/// References the Menu instance.
public
private(set)
lazy
var
menu
:
Menu
=
Menu
(
origin
:
CGPointZero
)
public
private(set)
lazy
var
menu
:
Menu
=
Menu
()
/**
Prepares the view instance when intialized. When subclassing,
...
...
@@ -98,15 +97,18 @@ public class MenuView : MaterialPulseView {
guard
!
hidden
else
{
return
nil
}
for
v
in
subviews
{
let
p
:
CGPoint
=
v
.
convertPoint
(
point
,
fromView
:
self
)
if
CGRectContainsPoint
(
v
.
bounds
,
p
)
{
return
v
.
hitTest
(
p
,
withEvent
:
event
)
}
}
(
delegate
as?
MenuViewDelegate
)?
.
menuViewDidTapOutside
?(
self
)
// if menu.opened {
// (delegate as? MenuViewDelegate)?.menuViewDidTapOutside?(self)
// }
return
super
.
hitTest
(
point
,
withEvent
:
event
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment