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
fdf87ffa
Commit
fdf87ffa
authored
Feb 07, 2016
by
danieldahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added orientation change in example
parent
bfa2cd30
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
34 deletions
+44
-34
Examples/Programmatic/MenuView/MenuView/Info.plist
+3
-0
Examples/Programmatic/MenuView/MenuView/ViewController.swift
+20
-13
Sources/MenuLayout.swift
+21
-21
No files found.
Examples/Programmatic/MenuView/MenuView/Info.plist
View file @
fdf87ffa
...
...
@@ -31,6 +31,9 @@
<
k
e
y
>
UISupportedInterfaceOrientations
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
string
>
UIInterfaceOrientationPortraitUpsideDown
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UISupportedInterfaceOrientations
~
ipad
<
/k
e
y
>
<
a
rr
a
y
>
...
...
Examples/Programmatic/MenuView/MenuView/ViewController.swift
View file @
fdf87ffa
...
...
@@ -36,7 +36,7 @@ import UIKit
import
Material
class
ViewController
:
UIViewController
{
private
var
menu
View
:
MenuLayout
!
private
var
menu
Layout
:
MenuLayout
!
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
...
...
@@ -44,11 +44,22 @@ class ViewController: UIViewController {
prepareMenuLayoutExample
()
}
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
}
override
func
viewWillTransitionToSize
(
size
:
CGSize
,
withTransitionCoordinator
coordinator
:
UIViewControllerTransitionCoordinator
)
{
super
.
viewWillTransitionToSize
(
size
,
withTransitionCoordinator
:
coordinator
)
menuLayout
.
width
=
size
.
width
menuLayout
.
height
=
size
.
height
menuLayout
.
reloadLayout
()
}
internal
func
handleOpenMenuLayout
()
{
if
menu
View
.
opened
{
menu
View
.
close
()
if
menu
Layout
.
opened
{
menu
Layout
.
close
()
}
else
{
menu
View
.
open
()
{
(
item
:
MenuLayoutItem
)
in
menu
Layout
.
open
()
{
(
item
:
MenuLayoutItem
)
in
(
item
.
button
as?
MaterialButton
)?
.
pulse
()
}
}
...
...
@@ -63,7 +74,7 @@ class ViewController: UIViewController {
private
func
prepareMenuLayoutExample
()
{
let
btn
:
FlatButton
=
FlatButton
(
frame
:
CGRectMake
(
100
,
100
,
100
,
100
))
btn
.
backgroundColor
=
MaterialColor
.
red
.
base
view
.
addSubview
(
btn
)
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_add_white"
)
let
btn1
:
FabButton
=
FabButton
()
...
...
@@ -94,15 +105,11 @@ class ViewController: UIViewController {
btn4
.
setImage
(
image
,
forState
:
.
Highlighted
)
view
.
addSubview
(
btn4
)
menuView
=
MenuLayout
()
menuView
.
menuPosition
=
.
TopRight
menuView
.
menuDirection
=
.
Left
menuView
.
baseSize
=
CGSizeMake
(
36
,
36
)
menuView
.
itemSize
=
CGSizeMake
(
36
,
36
)
view
.
addSubview
(
btn
)
menuLayout
=
MenuLayout
()
menuLayout
.
baseSize
=
CGSizeMake
(
48
,
48
)
menuLayout
.
itemSize
=
CGSizeMake
(
36
,
36
)
menu
View
.
menuI
tems
=
[
menu
Layout
.
i
tems
=
[
MenuLayoutItem
(
button
:
btn1
),
MenuLayoutItem
(
button
:
btn2
),
MenuLayoutItem
(
button
:
btn3
),
...
...
Sources/MenuLayout.swift
View file @
fdf87ffa
...
...
@@ -65,19 +65,19 @@ public class MenuLayout {
public
private(set)
var
opened
:
Bool
=
false
/// The position of the menu.
public
var
menuP
osition
:
MenuLayoutPosition
=
.
BottomRight
{
public
var
p
osition
:
MenuLayoutPosition
=
.
BottomRight
{
didSet
{
reload
View
()
reload
Layout
()
}
}
/// The direction in which the animation opens the menu.
public
var
menuD
irection
:
MenuLayoutDirection
=
.
Up
public
var
d
irection
:
MenuLayoutDirection
=
.
Up
/// An Array of MenuLayoutItems.
public
var
menuI
tems
:
Array
<
MenuLayoutItem
>
?
{
public
var
i
tems
:
Array
<
MenuLayoutItem
>
?
{
didSet
{
reload
View
()
reload
Layout
()
}
}
...
...
@@ -89,8 +89,8 @@ public class MenuLayout {
}
public
func
reload
View
()
{
switch
menuP
osition
{
public
func
reload
Layout
()
{
switch
p
osition
{
case
.
TopLeft
:
layoutTopLeft
()
case
.
TopRight
:
...
...
@@ -103,7 +103,7 @@ public class MenuLayout {
}
public
func
open
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
switch
menuD
irection
{
switch
d
irection
{
case
.
Up
:
openUpAnimation
(
completion
)
case
.
Down
:
...
...
@@ -116,7 +116,7 @@ public class MenuLayout {
}
public
func
close
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
switch
menuD
irection
{
switch
d
irection
{
case
.
Up
:
closeUpAnimation
(
completion
)
case
.
Down
:
...
...
@@ -129,7 +129,7 @@ public class MenuLayout {
}
private
func
openUpAnimation
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
var
base
:
MenuLayoutItem
?
for
var
i
:
Int
=
1
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
if
nil
==
base
{
...
...
@@ -151,7 +151,7 @@ public class MenuLayout {
}
public
func
closeUpAnimation
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
for
var
i
:
Int
=
1
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
let
item
:
MenuLayoutItem
=
v
[
i
]
UIView
.
animateWithDuration
(
0.15
,
...
...
@@ -169,7 +169,7 @@ public class MenuLayout {
}
private
func
openDownAnimation
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
var
base
:
MenuLayoutItem
?
for
var
i
:
Int
=
1
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
if
nil
==
base
{
...
...
@@ -191,7 +191,7 @@ public class MenuLayout {
}
public
func
closeDownAnimation
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
for
var
i
:
Int
=
1
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
let
item
:
MenuLayoutItem
=
v
[
i
]
UIView
.
animateWithDuration
(
0.15
,
...
...
@@ -209,7 +209,7 @@ public class MenuLayout {
}
private
func
openLeftAnimation
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
var
base
:
MenuLayoutItem
?
for
var
i
:
Int
=
1
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
if
nil
==
base
{
...
...
@@ -231,7 +231,7 @@ public class MenuLayout {
}
public
func
closeLeftAnimation
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
for
var
i
:
Int
=
1
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
let
item
:
MenuLayoutItem
=
v
[
i
]
UIView
.
animateWithDuration
(
0.15
,
...
...
@@ -249,7 +249,7 @@ public class MenuLayout {
}
private
func
openRightAnimation
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
var
base
:
MenuLayoutItem
?
for
var
i
:
Int
=
1
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
if
nil
==
base
{
...
...
@@ -271,7 +271,7 @@ public class MenuLayout {
}
public
func
closeRightAnimation
(
completion
:
((
MenuLayoutItem
)
->
Void
)?
=
nil
)
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
for
var
i
:
Int
=
1
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
let
item
:
MenuLayoutItem
=
v
[
i
]
UIView
.
animateWithDuration
(
0.15
,
...
...
@@ -289,7 +289,7 @@ public class MenuLayout {
}
private
func
layoutTopLeft
()
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
for
var
i
:
Int
=
0
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
let
item
:
MenuLayoutItem
=
v
[
i
]
if
0
==
i
{
...
...
@@ -309,7 +309,7 @@ public class MenuLayout {
}
private
func
layoutTopRight
()
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
for
var
i
:
Int
=
0
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
let
item
:
MenuLayoutItem
=
v
[
i
]
if
0
==
i
{
...
...
@@ -329,7 +329,7 @@ public class MenuLayout {
}
private
func
layoutBottomLeft
()
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
for
var
i
:
Int
=
0
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
let
item
:
MenuLayoutItem
=
v
[
i
]
if
0
==
i
{
...
...
@@ -349,7 +349,7 @@ public class MenuLayout {
}
private
func
layoutBottomRight
()
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
menuI
tems
{
if
let
v
:
Array
<
MenuLayoutItem
>
=
i
tems
{
for
var
i
:
Int
=
0
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
let
item
:
MenuLayoutItem
=
v
[
i
]
if
0
==
i
{
...
...
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