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
ca919cfe
Unverified
Commit
ca919cfe
authored
Sep 08, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: updated MenuView and Menu to now be one object
parent
159165b9
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
258 additions
and
329 deletions
+258
-329
Material.xcodeproj/project.pbxproj
+6
-12
Sources/iOS/Menu.swift
+222
-186
Sources/iOS/MenuController.swift
+27
-13
Sources/iOS/MenuView.swift
+0
-117
Sources/iOS/PhotoLibraryController.swift
+3
-1
No files found.
Material.xcodeproj/project.pbxproj
View file @
ca919cfe
...
...
@@ -71,8 +71,7 @@
96BCB7D31CB40DC500C806FE
/* MaterialTextLayer.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78A1CB40DC500C806FE
/* MaterialTextLayer.swift */
;
};
96BCB7D41CB40DC500C806FE
/* TransitionAnimation.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78B1CB40DC500C806FE
/* TransitionAnimation.swift */
;
};
96BCB7D51CB40DC500C806FE
/* View.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78C1CB40DC500C806FE
/* View.swift */
;
};
96BCB7D61CB40DC500C806FE
/* Menu.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78D1CB40DC500C806FE
/* Menu.swift */
;
};
96BCB7D71CB40DC500C806FE
/* MenuView.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78E1CB40DC500C806FE
/* MenuView.swift */
;
};
96BCB7D71CB40DC500C806FE
/* Menu.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78E1CB40DC500C806FE
/* Menu.swift */
;
};
96BCB7D81CB40DC500C806FE
/* MenuController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78F1CB40DC500C806FE
/* MenuController.swift */
;
};
96BCB7D91CB40DC500C806FE
/* NavigationBar.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7901CB40DC500C806FE
/* NavigationBar.swift */
;
};
96BCB7DA1CB40DC500C806FE
/* NavigationController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7911CB40DC500C806FE
/* NavigationController.swift */
;
};
...
...
@@ -140,8 +139,7 @@
96BCB83B1CB4115200C806FE
/* NavigationDrawerController.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7971CB40DC500C806FE
/* NavigationDrawerController.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB83C1CB4115200C806FE
/* BarView.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7981CB40DC500C806FE
/* BarView.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB83D1CB4115200C806FE
/* RootController.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB7991CB40DC500C806FE
/* RootController.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB83E1CB4115200C806FE
/* Menu.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78D1CB40DC500C806FE
/* Menu.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB83F1CB4115200C806FE
/* MenuView.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78E1CB40DC500C806FE
/* MenuView.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB83F1CB4115200C806FE
/* Menu.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78E1CB40DC500C806FE
/* Menu.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8401CB4115200C806FE
/* MenuController.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB78F1CB40DC500C806FE
/* MenuController.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8411CB4115200C806FE
/* TabBar.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB79A1CB40DC500C806FE
/* TabBar.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
96BCB8421CB4115200C806FE
/* Toolbar.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96BCB79F1CB40DC500C806FE
/* Toolbar.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
...
...
@@ -266,8 +264,7 @@
96BCB78A1CB40DC500C806FE
/* MaterialTextLayer.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialTextLayer.swift
;
sourceTree
=
"<group>"
;
};
96BCB78B1CB40DC500C806FE
/* TransitionAnimation.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
TransitionAnimation.swift
;
sourceTree
=
"<group>"
;
};
96BCB78C1CB40DC500C806FE
/* View.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
View.swift
;
sourceTree
=
"<group>"
;
};
96BCB78D1CB40DC500C806FE
/* Menu.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Menu.swift
;
sourceTree
=
"<group>"
;
};
96BCB78E1CB40DC500C806FE
/* MenuView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
indentWidth
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MenuView.swift
;
sourceTree
=
"<group>"
;
tabWidth
=
4
;
};
96BCB78E1CB40DC500C806FE
/* Menu.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
indentWidth
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Menu.swift
;
sourceTree
=
"<group>"
;
tabWidth
=
4
;
};
96BCB78F1CB40DC500C806FE
/* MenuController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MenuController.swift
;
sourceTree
=
"<group>"
;
};
96BCB7901CB40DC500C806FE
/* NavigationBar.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
NavigationBar.swift
;
sourceTree
=
"<group>"
;
};
96BCB7911CB40DC500C806FE
/* NavigationController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
NavigationController.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -436,8 +433,7 @@
963FBF021D6696D0008F8512
/* Menu */
=
{
isa
=
PBXGroup
;
children
=
(
96BCB78D1CB40DC500C806FE
/* Menu.swift */
,
96BCB78E1CB40DC500C806FE
/* MenuView.swift */
,
96BCB78E1CB40DC500C806FE
/* Menu.swift */
,
96BCB78F1CB40DC500C806FE
/* MenuController.swift */
,
);
name
=
Menu
;
...
...
@@ -818,8 +814,7 @@
96BCB83B1CB4115200C806FE
/* NavigationDrawerController.swift in Headers */
,
96BCB83C1CB4115200C806FE
/* BarView.swift in Headers */
,
96BCB83D1CB4115200C806FE
/* RootController.swift in Headers */
,
96BCB83E1CB4115200C806FE
/* Menu.swift in Headers */
,
96BCB83F1CB4115200C806FE
/* MenuView.swift in Headers */
,
96BCB83F1CB4115200C806FE
/* Menu.swift in Headers */
,
96BCB8401CB4115200C806FE
/* MenuController.swift in Headers */
,
96BCB8411CB4115200C806FE
/* TabBar.swift in Headers */
,
96BCB8421CB4115200C806FE
/* Toolbar.swift in Headers */
,
...
...
@@ -1051,7 +1046,6 @@
96BCB7DF1CB40DC500C806FE
/* SearchBarController.swift in Sources */
,
96BCB7D31CB40DC500C806FE
/* MaterialTextLayer.swift in Sources */
,
96BCB7C11CB40DC500C806FE
/* Depth.swift in Sources */
,
96BCB7D61CB40DC500C806FE
/* Menu.swift in Sources */
,
96BCB7E61CB40DC500C806FE
/* TextStorage.swift in Sources */
,
96BCB7A91CB40DC500C806FE
/* FlatButton.swift in Sources */
,
96BCB7CA1CB40DC500C806FE
/* Layout.swift in Sources */
,
...
...
@@ -1101,7 +1095,7 @@
96BCB7E21CB40DC500C806FE
/* RootController.swift in Sources */
,
96BCB7DC1CB40DC500C806FE
/* RaisedButton.swift in Sources */
,
96BCB7DD1CB40DC500C806FE
/* RobotoFont.swift in Sources */
,
96BCB7D71CB40DC500C806FE
/* Menu
View
.swift in Sources */
,
96BCB7D71CB40DC500C806FE
/* Menu.swift in Sources */
,
966ECF2A1CF4C20100BB0BDF
/* CollectionReusableView.swift in Sources */
,
96BCB7E51CB40DC500C806FE
/* TextField.swift in Sources */
,
96BCB7D21CB40DC500C806FE
/* TableViewCell.swift in Sources */
,
...
...
Sources/iOS/Menu.swift
View file @
ca919cfe
...
...
@@ -38,71 +38,73 @@ public enum MenuDirection: Int {
case
right
}
public
class
Menu
{
/// A Boolean that indicates if the menu is open or not.
public
private(set)
var
isOpened
=
false
@objc(MenuDelegate)
public
protocol
MenuDelegate
{
/// Gets called when the user taps outside menu buttons.
@objc
optional
func
menu
(
menu
:
Menu
,
tappedAt
point
:
CGPoint
)
}
/// The rectangular bounds that the menu animates.
public
var
origin
:
CGPoint
{
didSet
{
reload
()
}
}
open
class
Menu
:
View
{
/// A Boolean that indicates if the menu is open or not.
open
private(set)
var
isOpened
=
false
/// A preset wrapper around interimSpace.
public
var
interimSpacePreset
=
InterimSpacePreset
.
none
{
open
var
interimSpacePreset
=
InterimSpacePreset
.
none
{
didSet
{
interimSpace
=
InterimSpacePresetToValue
(
preset
:
interimSpacePreset
)
}
}
/// The space between views.
public
var
interimSpace
:
InterimSpace
{
open
var
interimSpace
:
InterimSpace
=
0
{
didSet
{
reload
()
}
}
/// Enables the animations for the Menu.
public
var
isEnabled
=
true
open
private(set)
var
isEnabled
=
true
/// The direction in which the animation opens the menu.
public
var
direction
:
MenuDirection
=
.
up
{
open
var
direction
=
MenuDirection
.
up
{
didSet
{
reload
()
}
}
/// An Array of UIViews.
public
var
views
:
[
UIView
]?
{
open
var
views
=
[
UIView
]()
{
didSet
{
reload
()
}
}
/// An Optional base view size.
open
var
baseSize
=
CGSize
(
width
:
48
,
height
:
48
)
/// Size of views, not including the first view.
public
var
itemSize
:
CG
Size
=
CGSize
(
width
:
48
,
height
:
48
)
open
var
item
Size
=
CGSize
(
width
:
48
,
height
:
48
)
/// An Optional base view size.
public
var
baseSize
:
CGSize
?
/**
Initializer.
- Parameter coder aDecoder: An NSCoder.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
}
/**
Initializer.
- Parameter origin: The origin position of the Menu.
- Parameter interimSpace: The interimSpace size between views.
*/
public
init
(
origin
:
CGPoint
,
interimSpace
:
InterimSpace
=
16
)
{
self
.
origin
=
origin
public
convenience
init
(
interimSpace
:
InterimSpace
=
16
)
{
self
.
init
()
self
.
interimSpace
=
interimSpace
}
/// Convenience initializer.
public
convenience
init
()
{
self
.
init
(
origin
:
.
zero
)
}
/// Reload the view layout.
public
func
reload
()
{
open
func
reload
()
{
isOpened
=
false
layoutButtons
()
}
...
...
@@ -117,7 +119,7 @@ public class Menu {
- Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation.
*/
public
func
open
(
duration
:
TimeInterval
=
0.15
,
delay
:
TimeInterval
=
0
,
usingSpringWithDamping
:
CGFloat
=
0.5
,
initialSpringVelocity
:
CGFloat
=
0
,
options
:
UIViewAnimationOptions
=
[],
animations
:
((
UIView
)
->
Void
)?
=
nil
,
completion
:
((
UIView
)
->
Void
)?
=
nil
)
{
open
func
open
(
duration
:
TimeInterval
=
0.15
,
delay
:
TimeInterval
=
0
,
usingSpringWithDamping
:
CGFloat
=
0.5
,
initialSpringVelocity
:
CGFloat
=
0
,
options
:
UIViewAnimationOptions
=
[],
animations
:
((
UIView
)
->
Void
)?
=
nil
,
completion
:
((
UIView
)
->
Void
)?
=
nil
)
{
if
isEnabled
{
disable
()
switch
direction
{
...
...
@@ -143,7 +145,7 @@ public class Menu {
- Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation.
*/
public
func
close
(
duration
:
TimeInterval
=
0.15
,
delay
:
TimeInterval
=
0
,
usingSpringWithDamping
:
CGFloat
=
0.5
,
initialSpringVelocity
:
CGFloat
=
0
,
options
:
UIViewAnimationOptions
=
[],
animations
:
((
UIView
)
->
Void
)?
=
nil
,
completion
:
((
UIView
)
->
Void
)?
=
nil
)
{
open
func
close
(
duration
:
TimeInterval
=
0.15
,
delay
:
TimeInterval
=
0
,
usingSpringWithDamping
:
CGFloat
=
0.5
,
initialSpringVelocity
:
CGFloat
=
0
,
options
:
UIViewAnimationOptions
=
[],
animations
:
((
UIView
)
->
Void
)?
=
nil
,
completion
:
((
UIView
)
->
Void
)?
=
nil
)
{
if
isEnabled
{
disable
()
switch
direction
{
...
...
@@ -170,35 +172,40 @@ public class Menu {
- Parameter completion: A completion block to execute on each view's animation.
*/
private
func
openUpAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
if
let
v
=
views
{
var
base
:
UIView
?
for
i
in
1
..<
v
.
count
{
if
nil
==
base
{
base
=
v
[
0
]
guard
let
base
=
views
.
first
else
{
return
}
let
view
:
UIView
=
v
[
i
]
view
.
isHidden
=
false
for
i
in
1
..<
views
.
count
{
let
v
=
views
[
i
]
v
.
isHidden
=
false
UIView
.
animate
(
withDuration
:
Double
(
i
)
*
duration
,
delay
:
delay
,
usingSpringWithDamping
:
usingSpringWithDamping
,
initialSpringVelocity
:
initialSpringVelocity
,
options
:
options
,
animations
:
{
[
weak
self
]
in
if
let
s
:
Menu
=
self
{
view
.
alpha
=
1
view
.
y
=
base
!.
y
-
CGFloat
(
i
)
*
s
.
itemSize
.
height
-
CGFloat
(
i
)
*
s
.
interimSpace
animations
?(
view
)
animations
:
{
[
weak
self
,
base
=
base
]
in
guard
let
s
=
self
else
{
return
}
v
.
alpha
=
1
v
.
y
=
base
.
y
-
CGFloat
(
i
)
*
s
.
itemSize
.
height
-
CGFloat
(
i
)
*
s
.
interimSpace
animations
?(
v
)
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
s
.
enable
(
view
:
view
)
if
view
==
v
.
last
{
s
.
isOpened
=
true
}
completion
?(
view
)
guard
let
s
=
self
else
{
return
}
s
.
enable
(
view
:
v
)
if
v
==
s
.
views
.
last
{
s
.
isOpened
=
true
}
completion
?(
v
)
}
}
}
...
...
@@ -213,10 +220,10 @@ public class Menu {
- Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation.
*/
public
func
closeUpAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
if
let
v
=
views
{
for
i
in
1
..<
v
.
count
{
let
view
:
UIView
=
v
[
i
]
private
func
closeUpAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
for
i
in
1
..<
views
.
count
{
let
v
=
views
[
i
]
UIView
.
animate
(
withDuration
:
Double
(
i
)
*
duration
,
delay
:
delay
,
...
...
@@ -224,21 +231,27 @@ public class Menu {
initialSpringVelocity
:
initialSpringVelocity
,
options
:
options
,
animations
:
{
[
weak
self
]
in
if
let
s
:
Menu
=
self
{
view
.
alpha
=
0
view
.
y
=
s
.
origin
.
y
animations
?(
view
)
guard
let
s
=
self
else
{
return
}
v
.
alpha
=
0
v
.
y
=
s
.
y
animations
?(
v
)
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
view
.
isHidden
=
true
s
.
enable
(
view
:
view
)
if
view
==
v
.
last
{
s
.
isOpened
=
false
}
completion
?(
view
)
guard
let
s
=
self
else
{
return
}
v
.
isHidden
=
true
s
.
enable
(
view
:
v
)
if
v
==
s
.
views
.
last
{
s
.
isOpened
=
false
}
completion
?(
v
)
}
}
}
...
...
@@ -254,37 +267,41 @@ public class Menu {
- Parameter completion: A completion block to execute on each view's animation.
*/
private
func
openDownAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
if
let
v
=
views
{
var
base
:
UIView
?
for
i
in
1
..<
v
.
count
{
if
nil
==
base
{
base
=
v
[
0
]
guard
let
base
=
views
.
first
else
{
return
}
let
view
:
UIView
=
v
[
i
]
view
.
isHidden
=
false
for
i
in
1
..<
views
.
count
{
let
v
=
views
[
i
]
v
.
isHidden
=
false
let
h
:
CGFloat
=
nil
==
baseSize
?
itemSize
.
height
:
baseSize
!
.
height
let
h
=
baseSize
.
height
UIView
.
animate
(
withDuration
:
Double
(
i
)
*
duration
,
delay
:
delay
,
usingSpringWithDamping
:
usingSpringWithDamping
,
initialSpringVelocity
:
initialSpringVelocity
,
options
:
options
,
animations
:
{
[
weak
self
]
in
if
let
s
:
Menu
=
self
{
view
.
alpha
=
1
view
.
y
=
base
!.
y
+
h
+
CGFloat
(
i
-
1
)
*
s
.
itemSize
.
height
+
CGFloat
(
i
)
*
s
.
interimSpace
animations
?(
view
)
animations
:
{
[
weak
self
,
base
=
base
]
in
guard
let
s
=
self
else
{
return
}
v
.
alpha
=
1
v
.
y
=
base
.
y
+
h
+
CGFloat
(
i
-
1
)
*
s
.
itemSize
.
height
+
CGFloat
(
i
)
*
s
.
interimSpace
animations
?(
v
)
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
s
.
enable
(
view
:
view
)
if
view
==
v
.
last
{
s
.
isOpened
=
true
}
completion
?(
view
)
guard
let
s
=
self
else
{
return
}
s
.
enable
(
view
:
v
)
if
v
==
s
.
views
.
last
{
s
.
isOpened
=
true
}
completion
?(
v
)
}
}
}
...
...
@@ -299,33 +316,38 @@ public class Menu {
- Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation.
*/
public
func
closeDownAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
if
let
v
=
views
{
for
i
in
1
..<
v
.
count
{
let
view
:
UIView
=
v
[
i
]
private
func
closeDownAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
for
i
in
1
..<
views
.
count
{
let
v
=
views
[
i
]
let
h
:
CGFloat
=
nil
==
baseSize
?
itemSize
.
height
:
baseSize
!
.
height
let
h
=
baseSize
.
height
UIView
.
animate
(
withDuration
:
Double
(
i
)
*
duration
,
delay
:
delay
,
usingSpringWithDamping
:
usingSpringWithDamping
,
initialSpringVelocity
:
initialSpringVelocity
,
options
:
options
,
animations
:
{
[
weak
self
]
in
if
let
s
:
Menu
=
self
{
view
.
alpha
=
0
view
.
y
=
s
.
origin
.
y
+
h
animations
?(
view
)
guard
let
s
=
self
else
{
return
}
v
.
alpha
=
0
v
.
y
=
s
.
y
+
h
animations
?(
v
)
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
view
.
isHidden
=
true
s
.
enable
(
view
:
view
)
if
view
==
v
.
last
{
s
.
isOpened
=
false
}
completion
?(
view
)
guard
let
s
=
self
else
{
return
}
v
.
isHidden
=
true
s
.
enable
(
view
:
v
)
if
v
==
s
.
views
.
last
{
s
.
isOpened
=
false
}
completion
?(
v
)
}
}
}
...
...
@@ -341,36 +363,40 @@ public class Menu {
- Parameter completion: A completion block to execute on each view's animation.
*/
private
func
openLeftAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
if
let
v
=
views
{
var
base
:
UIView
?
for
i
in
1
..<
v
.
count
{
if
nil
==
base
{
base
=
v
[
0
]
guard
let
base
=
views
.
first
else
{
return
}
let
view
:
UIView
=
v
[
i
]
view
.
isHidden
=
false
for
i
in
1
..<
views
.
count
{
let
v
=
views
[
i
]
v
.
isHidden
=
false
UIView
.
animate
(
withDuration
:
Double
(
i
)
*
duration
,
delay
:
delay
,
usingSpringWithDamping
:
usingSpringWithDamping
,
initialSpringVelocity
:
initialSpringVelocity
,
options
:
options
,
animations
:
{
[
weak
self
]
in
if
let
s
:
Menu
=
self
{
view
.
alpha
=
1
view
.
x
=
base
!.
x
-
CGFloat
(
i
)
*
s
.
itemSize
.
width
-
CGFloat
(
i
)
*
s
.
interimSpace
animations
?(
view
)
animations
:
{
[
weak
self
,
base
=
base
]
in
guard
let
s
=
self
else
{
return
}
v
.
alpha
=
1
v
.
x
=
base
.
x
-
CGFloat
(
i
)
*
s
.
itemSize
.
width
-
CGFloat
(
i
)
*
s
.
interimSpace
animations
?(
v
)
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
s
.
enable
(
view
:
view
)
if
view
==
v
.
last
{
s
.
isOpened
=
true
}
completion
?(
view
)
guard
let
s
=
self
else
{
return
}
s
.
enable
(
view
:
v
)
if
v
==
s
.
views
.
last
{
s
.
isOpened
=
true
}
completion
?(
v
)
}
}
}
...
...
@@ -385,31 +411,37 @@ public class Menu {
- Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation.
*/
public
func
closeLeftAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
if
let
v
=
views
{
for
i
in
1
..<
v
.
count
{
let
view
:
UIView
=
v
[
i
]
private
func
closeLeftAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
for
i
in
1
..<
views
.
count
{
let
v
=
views
[
i
]
UIView
.
animate
(
withDuration
:
Double
(
i
)
*
duration
,
delay
:
delay
,
usingSpringWithDamping
:
usingSpringWithDamping
,
initialSpringVelocity
:
initialSpringVelocity
,
options
:
options
,
animations
:
{
[
weak
self
]
in
if
let
s
:
Menu
=
self
{
view
.
alpha
=
0
view
.
x
=
s
.
origin
.
x
animations
?(
view
)
guard
let
s
=
self
else
{
return
}
v
.
alpha
=
0
v
.
x
=
s
.
x
animations
?(
v
)
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
view
.
isHidden
=
true
s
.
enable
(
view
:
view
)
if
view
==
v
.
last
{
s
.
isOpened
=
false
}
completion
?(
view
)
guard
let
s
=
self
else
{
return
}
v
.
isHidden
=
true
s
.
enable
(
view
:
v
)
if
v
==
s
.
views
.
last
{
s
.
isOpened
=
false
}
completion
?(
v
)
}
}
}
...
...
@@ -425,36 +457,41 @@ public class Menu {
- Parameter completion: A completion block to execute on each view's animation.
*/
private
func
openRightAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
if
let
v
=
views
{
var
base
:
UIView
?
for
i
in
1
..<
v
.
count
{
if
nil
==
base
{
base
=
v
[
0
]
guard
let
base
=
views
.
first
else
{
return
}
let
view
:
UIView
=
v
[
i
]
view
.
isHidden
=
false
let
h
:
CGFloat
=
nil
==
baseSize
?
itemSize
.
height
:
baseSize
!.
height
for
i
in
1
..<
views
.
count
{
let
v
=
views
[
i
]
v
.
isHidden
=
false
let
h
=
baseSize
.
height
UIView
.
animate
(
withDuration
:
Double
(
i
)
*
duration
,
delay
:
delay
,
usingSpringWithDamping
:
usingSpringWithDamping
,
initialSpringVelocity
:
initialSpringVelocity
,
options
:
options
,
animations
:
{
[
weak
self
]
in
if
let
s
:
Menu
=
self
{
view
.
alpha
=
1
view
.
x
=
base
!.
x
+
h
+
CGFloat
(
i
-
1
)
*
s
.
itemSize
.
width
+
CGFloat
(
i
)
*
s
.
interimSpace
animations
?(
view
)
animations
:
{
[
weak
self
,
base
=
base
]
in
guard
let
s
=
self
else
{
return
}
v
.
alpha
=
1
v
.
x
=
base
.
x
+
h
+
CGFloat
(
i
-
1
)
*
s
.
itemSize
.
width
+
CGFloat
(
i
)
*
s
.
interimSpace
animations
?(
v
)
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
s
.
enable
(
view
:
view
)
if
view
==
v
.
last
{
s
.
isOpened
=
true
}
completion
?(
view
)
guard
let
s
=
self
else
{
return
}
s
.
enable
(
view
:
v
)
if
v
==
s
.
views
.
last
{
s
.
isOpened
=
true
}
completion
?(
v
)
}
}
}
...
...
@@ -469,66 +506,66 @@ public class Menu {
- Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation.
*/
public
func
closeRightAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
if
let
v
=
views
{
for
i
in
1
..<
v
.
count
{
let
view
:
UIView
=
v
[
i
]
private
func
closeRightAnimation
(
duration
:
TimeInterval
,
delay
:
TimeInterval
,
usingSpringWithDamping
:
CGFloat
,
initialSpringVelocity
:
CGFloat
,
options
:
UIViewAnimationOptions
,
animations
:
((
UIView
)
->
Void
)?,
completion
:
((
UIView
)
->
Void
)?)
{
for
i
in
1
..<
views
.
count
{
let
v
=
views
[
i
]
let
w
=
baseSize
.
width
let
w
:
CGFloat
=
nil
==
baseSize
?
itemSize
.
width
:
baseSize
!.
width
UIView
.
animate
(
withDuration
:
Double
(
i
)
*
duration
,
delay
:
delay
,
usingSpringWithDamping
:
usingSpringWithDamping
,
initialSpringVelocity
:
initialSpringVelocity
,
options
:
options
,
animations
:
{
[
weak
self
]
in
if
let
s
:
Menu
=
self
{
view
.
alpha
=
0
view
.
x
=
s
.
origin
.
x
+
w
animations
?(
view
)
guard
let
s
=
self
else
{
return
}
v
.
alpha
=
0
v
.
x
=
s
.
x
+
w
animations
?(
v
)
})
{
[
weak
self
]
_
in
if
let
s
:
Menu
=
self
{
view
.
isHidden
=
true
s
.
enable
(
view
:
view
)
if
view
==
v
.
last
{
s
.
isOpened
=
false
}
completion
?(
view
)
guard
let
s
=
self
else
{
return
}
v
.
isHidden
=
true
s
.
enable
(
view
:
v
)
if
v
==
s
.
views
.
last
{
s
.
isOpened
=
false
}
completion
?(
v
)
}
}
}
/// Layout the views.
private
func
layoutButtons
()
{
if
let
v
=
views
{
let
size
:
CGSize
=
nil
==
baseSize
?
itemSize
:
baseSize
!
for
i
in
0
..<
v
.
count
{
let
view
:
UIView
=
v
[
i
]
for
i
in
0
..<
views
.
count
{
let
v
=
views
[
i
]
if
0
==
i
{
view
.
frame
.
size
=
size
view
.
frame
.
origin
=
origin
view
.
layer
.
zPosition
=
10000
v
.
frame
.
size
=
baseSize
v
.
layer
.
zPosition
=
10000
}
else
{
view
.
alpha
=
0
view
.
isHidden
=
true
view
.
frame
.
size
=
itemSize
view
.
x
=
origin
.
x
+
(
size
.
width
-
itemSize
.
width
)
/
2
view
.
y
=
origin
.
y
+
(
size
.
height
-
itemSize
.
height
)
/
2
view
.
layer
.
zPosition
=
CGFloat
(
10000
-
v
.
count
-
i
)
}
v
.
alpha
=
0
v
.
isHidden
=
true
v
.
frame
.
size
=
itemSize
v
.
x
=
x
+
(
baseSize
.
width
-
itemSize
.
width
)
/
2
v
.
y
=
y
+
(
baseSize
.
height
-
itemSize
.
height
)
/
2
v
.
layer
.
zPosition
=
CGFloat
(
10000
-
views
.
count
-
i
)
}
}
}
/// Disable the Menu if views exist.
private
func
disable
()
{
if
let
v
=
views
{
if
0
<
v
.
count
{
isEnabled
=
false
}
guard
0
<
views
.
count
else
{
return
}
isEnabled
=
false
}
/**
...
...
@@ -536,10 +573,9 @@ public class Menu {
- Parameter view: UIView that is passed in to compare.
*/
private
func
enable
(
view
:
UIView
)
{
if
let
v
=
views
{
if
view
==
v
.
last
{
isEnabled
=
true
}
guard
view
==
views
.
last
else
{
return
}
isEnabled
=
true
}
}
Sources/iOS/MenuController.swift
View file @
ca919cfe
...
...
@@ -49,35 +49,49 @@ extension UIViewController {
}
@IBDesignable
public
class
MenuController
:
RootController
{
open
class
MenuController
:
RootController
{
/// Reference to the MenuView.
public
private(set)
lazy
var
menuView
:
MenuView
=
MenuView
()
open
internal(set)
lazy
var
menu
:
Menu
=
Menu
()
/**
Opens the menu with a callback.
- Parameter completion: An Optional callback that is executed when
all menu items have been opened.
*/
public
func
openMenu
(
completion
:
(()
->
Void
)?
=
nil
)
{
open
func
open
(
completion
:
(()
->
Void
)?
=
nil
)
{
if
true
==
isUserInteractionEnabled
{
isUserInteractionEnabled
=
false
rootViewController
.
view
.
alpha
=
0.5
menuView
.
open
(
completion
:
completion
)
menu
.
open
{
[
weak
self
]
(
view
)
in
guard
let
s
=
self
else
{
return
}
if
view
==
s
.
menu
.
views
.
last
{
completion
?()
}
}
}
}
/**
Close
s the menu with a callback.
Open
s the menu with a callback.
- Parameter completion: An Optional callback that is executed when
all menu items have been closed.
*/
public
func
closeMenu
(
completion
:
(()
->
Void
)?
=
nil
)
{
open
func
close
(
completion
:
(()
->
Void
)?
=
nil
)
{
if
false
==
isUserInteractionEnabled
{
rootViewController
.
view
.
alpha
=
1
menuView
.
close
(
completion
:
{
[
weak
self
]
in
self
?
.
isUserInteractionEnabled
=
true
menu
.
open
{
[
weak
self
]
(
view
)
in
guard
let
s
=
self
else
{
return
}
if
view
==
s
.
menu
.
views
.
last
{
s
.
isUserInteractionEnabled
=
true
completion
?()
})
}
}
}
}
...
...
@@ -86,7 +100,7 @@ public class MenuController: RootController {
method. LayoutSubviews should be called immediately, unless you
have a certain need.
*/
public
override
func
layoutSubviews
()
{
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
rootViewController
.
view
.
frame
=
view
.
bounds
}
...
...
@@ -98,14 +112,14 @@ public class MenuController: RootController {
The super.prepareView method should always be called immediately
when subclassing.
*/
public
override
func
prepareView
()
{
open
override
func
prepareView
()
{
super
.
prepareView
()
prepareMenuView
()
}
/// Prepares the MenuView.
private
func
prepareMenuView
()
{
menu
View
.
zPosition
=
1000
view
.
addSubview
(
menu
View
)
menu
.
zPosition
=
1000
view
.
addSubview
(
menu
)
}
}
Sources/iOS/MenuView.swift
deleted
100644 → 0
View file @
159165b9
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import
UIKit
@objc(MenuViewDelegate)
public
protocol
MenuViewDelegate
{
/// Gets called when the user taps outside menu buttons.
@objc
optional
func
menuViewDidTapOutside
(
menuView
:
MenuView
)
}
open
class
MenuView
:
PulseView
{
/// References the Menu instance.
open
internal(set)
lazy
var
menu
:
Menu
=
Menu
()
/// A delegation reference.
open
weak
var
delegate
:
MenuViewDelegate
?
open
override
func
hitTest
(
_
point
:
CGPoint
,
with
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.
*/
guard
!
isHidden
else
{
return
nil
}
for
v
in
subviews
{
let
p
=
v
.
convert
(
point
,
from
:
self
)
if
v
.
bounds
.
contains
(
p
)
{
return
v
.
hitTest
(
p
,
with
:
event
)
}
}
if
menu
.
isOpened
{
delegate
?
.
menuViewDidTapOutside
?(
menuView
:
self
)
}
return
super
.
hitTest
(
point
,
with
:
event
)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
open
override
func
prepareView
()
{
super
.
prepareView
()
pulseAnimation
=
.
none
clipsToBounds
=
false
backgroundColor
=
nil
}
/**
Opens the menu with a callback.
- Parameter completion: An Optional callback that is executed when
all menu items have been opened.
*/
open
func
open
(
completion
:
(()
->
Void
)?
=
nil
)
{
if
true
==
menu
.
views
?
.
first
?
.
isUserInteractionEnabled
{
menu
.
views
?
.
first
?
.
isUserInteractionEnabled
=
false
menu
.
open
{
[
weak
self
]
(
v
:
UIView
)
in
if
self
?
.
menu
.
views
?
.
last
==
v
{
self
?
.
menu
.
views
?
.
first
?
.
isUserInteractionEnabled
=
true
completion
?()
}
}
}
}
/**
Closes the menu with a callback.
- Parameter completion: An Optional callback that is executed when
all menu items have been closed.
*/
open
func
close
(
completion
:
(()
->
Void
)?
=
nil
)
{
if
true
==
menu
.
views
?
.
first
?
.
isUserInteractionEnabled
{
menu
.
views
?
.
first
?
.
isUserInteractionEnabled
=
false
menu
.
close
{
[
weak
self
]
(
v
:
UIView
)
in
if
self
?
.
menu
.
views
?
.
last
==
v
{
self
?
.
menu
.
views
?
.
first
?
.
isUserInteractionEnabled
=
true
completion
?()
}
}
}
}
}
Sources/iOS/PhotoLibraryController.swift
View file @
ca919cfe
...
...
@@ -30,7 +30,7 @@
import
UIKit
open
class
PhotoLibraryController
:
UIViewController
,
PhotoLibraryDelegate
{
open
class
PhotoLibraryController
:
UIViewController
{
/// A reference to a PhotoLibrary.
public
private(set)
lazy
var
photoLibrary
:
PhotoLibrary
=
PhotoLibrary
()
...
...
@@ -58,3 +58,5 @@ open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate {
photoLibrary
.
delegate
=
self
}
}
extension
PhotoLibraryController
:
PhotoLibraryDelegate
{}
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