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
ae0a2079
Unverified
Commit
ae0a2079
authored
Apr 23, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved Motion extension to MotionBasicAnimation
parent
6050b9bc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
68 deletions
+115
-68
Sources/iOS/Material+Motion.swift
+12
-12
Sources/iOS/Material+MotionAnimation.swift
+59
-36
Sources/iOS/PageMenuController.swift
+44
-20
No files found.
Sources/iOS/Material+Motion.swift
View file @
ae0a2079
...
...
@@ -571,38 +571,38 @@ extension MotionAnimator {
var
snapshotAnimations
=
[
CABasicAnimation
]()
var
snapshotChildAnimations
=
[
CABasicAnimation
]()
let
sizeAnimation
=
Motion
.
size
(
to
.
bounds
.
size
)
let
cornerRadiusAnimation
=
Motion
.
corner
(
radius
:
to
.
layer
.
cornerRadius
)
let
sizeAnimation
=
Motion
BasicAnimation
.
size
(
to
.
bounds
.
size
)
let
cornerRadiusAnimation
=
Motion
BasicAnimation
.
corner
(
radius
:
to
.
layer
.
cornerRadius
)
snapshotAnimations
.
append
(
sizeAnimation
)
snapshotAnimations
.
append
(
cornerRadiusAnimation
)
snapshotAnimations
.
append
(
Motion
.
position
(
to
:
to
.
motionPosition
))
snapshotAnimations
.
append
(
Motion
.
transform
(
transform
:
to
.
motionTransform
))
snapshotAnimations
.
append
(
Motion
.
background
(
color
:
to
.
backgroundColor
??
.
clear
))
snapshotAnimations
.
append
(
Motion
.
border
(
color
:
to
.
borderColor
??
.
clear
))
snapshotAnimations
.
append
(
Motion
.
border
(
width
:
to
.
borderWidth
))
snapshotAnimations
.
append
(
Motion
BasicAnimation
.
position
(
to
:
to
.
motionPosition
))
snapshotAnimations
.
append
(
Motion
BasicAnimation
.
transform
(
transform
:
to
.
motionTransform
))
snapshotAnimations
.
append
(
Motion
BasicAnimation
.
background
(
color
:
to
.
backgroundColor
??
.
clear
))
snapshotAnimations
.
append
(
Motion
BasicAnimation
.
border
(
color
:
to
.
borderColor
??
.
clear
))
snapshotAnimations
.
append
(
Motion
BasicAnimation
.
border
(
width
:
to
.
borderWidth
))
if
let
path
=
to
.
layer
.
shadowPath
{
let
shadowPath
=
Motion
.
shadow
(
path
:
path
)
let
shadowPath
=
Motion
BasicAnimation
.
shadow
(
path
:
path
)
shadowPath
.
fromValue
=
fromView
.
layer
.
shadowPath
snapshotAnimations
.
append
(
shadowPath
)
}
let
shadowOffset
=
Motion
.
shadow
(
offset
:
to
.
layer
.
shadowOffset
)
let
shadowOffset
=
Motion
BasicAnimation
.
shadow
(
offset
:
to
.
layer
.
shadowOffset
)
shadowOffset
.
fromValue
=
fromView
.
layer
.
shadowOffset
snapshotAnimations
.
append
(
shadowOffset
)
let
shadowOpacity
=
Motion
.
shadow
(
opacity
:
to
.
layer
.
shadowOpacity
)
let
shadowOpacity
=
Motion
BasicAnimation
.
shadow
(
opacity
:
to
.
layer
.
shadowOpacity
)
shadowOpacity
.
fromValue
=
fromView
.
layer
.
shadowOpacity
snapshotAnimations
.
append
(
shadowOpacity
)
let
shadowRadius
=
Motion
.
shadow
(
radius
:
to
.
layer
.
shadowRadius
)
let
shadowRadius
=
Motion
BasicAnimation
.
shadow
(
radius
:
to
.
layer
.
shadowRadius
)
shadowRadius
.
fromValue
=
fromView
.
layer
.
shadowRadius
snapshotAnimations
.
append
(
shadowRadius
)
snapshotChildAnimations
.
append
(
cornerRadiusAnimation
)
snapshotChildAnimations
.
append
(
sizeAnimation
)
snapshotChildAnimations
.
append
(
Motion
.
position
(
x
:
to
.
bounds
.
width
/
2
,
y
:
to
.
bounds
.
height
/
2
))
snapshotChildAnimations
.
append
(
Motion
BasicAnimation
.
position
(
x
:
to
.
bounds
.
width
/
2
,
y
:
to
.
bounds
.
height
/
2
))
let
d
=
calculateAnimationTransitionDuration
(
animations
:
to
.
motionAnimations
)
...
...
Sources/iOS/Material+MotionAnimation.swift
View file @
ae0a2079
...
...
@@ -265,97 +265,97 @@ extension CALayer {
case
let
.
custom
(
animation
):
a
.
append
(
animation
)
case
let
.
backgroundColor
(
color
):
a
.
append
(
Motion
.
background
(
color
:
color
))
a
.
append
(
Motion
BasicAnimation
.
background
(
color
:
color
))
case
let
.
barTintColor
(
color
):
a
.
append
(
Motion
.
barTint
(
color
:
color
))
a
.
append
(
Motion
BasicAnimation
.
barTint
(
color
:
color
))
case
let
.
borderColor
(
color
):
a
.
append
(
Motion
.
border
(
color
:
color
))
a
.
append
(
Motion
BasicAnimation
.
border
(
color
:
color
))
case
let
.
borderWidth
(
width
):
a
.
append
(
Motion
.
border
(
width
:
width
))
a
.
append
(
Motion
BasicAnimation
.
border
(
width
:
width
))
case
let
.
cornerRadius
(
radius
):
a
.
append
(
Motion
.
corner
(
radius
:
radius
))
a
.
append
(
Motion
BasicAnimation
.
corner
(
radius
:
radius
))
case
let
.
transform
(
transform
):
a
.
append
(
Motion
.
transform
(
transform
:
transform
))
a
.
append
(
Motion
BasicAnimation
.
transform
(
transform
:
transform
))
case
let
.
rotationAngle
(
angle
):
let
rotate
=
Motion
.
rotation
(
angle
:
angle
)
let
rotate
=
Motion
BasicAnimation
.
rotation
(
angle
:
angle
)
a
.
append
(
rotate
)
case
let
.
rotationAngleX
(
angle
):
a
.
append
(
Motion
.
rotationX
(
angle
:
angle
))
a
.
append
(
Motion
BasicAnimation
.
rotationX
(
angle
:
angle
))
case
let
.
rotationAngleY
(
angle
):
a
.
append
(
Motion
.
rotationY
(
angle
:
angle
))
a
.
append
(
Motion
BasicAnimation
.
rotationY
(
angle
:
angle
))
case
let
.
rotationAngleZ
(
angle
):
a
.
append
(
Motion
.
rotationZ
(
angle
:
angle
))
a
.
append
(
Motion
BasicAnimation
.
rotationZ
(
angle
:
angle
))
case
let
.
spin
(
rotations
):
a
.
append
(
Motion
.
spin
(
rotations
:
rotations
))
a
.
append
(
Motion
BasicAnimation
.
spin
(
rotations
:
rotations
))
case
let
.
spinX
(
rotations
):
a
.
append
(
Motion
.
spinX
(
rotations
:
rotations
))
a
.
append
(
Motion
BasicAnimation
.
spinX
(
rotations
:
rotations
))
case
let
.
spinY
(
rotations
):
a
.
append
(
Motion
.
spinY
(
rotations
:
rotations
))
a
.
append
(
Motion
BasicAnimation
.
spinY
(
rotations
:
rotations
))
case
let
.
spinZ
(
rotations
):
a
.
append
(
Motion
.
spinZ
(
rotations
:
rotations
))
a
.
append
(
Motion
BasicAnimation
.
spinZ
(
rotations
:
rotations
))
case
let
.
scale
(
to
):
a
.
append
(
Motion
.
scale
(
to
:
to
))
a
.
append
(
Motion
BasicAnimation
.
scale
(
to
:
to
))
case
let
.
scaleX
(
to
):
a
.
append
(
Motion
.
scaleX
(
to
:
to
))
a
.
append
(
Motion
BasicAnimation
.
scaleX
(
to
:
to
))
case
let
.
scaleY
(
to
):
a
.
append
(
Motion
.
scaleY
(
to
:
to
))
a
.
append
(
Motion
BasicAnimation
.
scaleY
(
to
:
to
))
case
let
.
scaleZ
(
to
):
a
.
append
(
Motion
.
scaleZ
(
to
:
to
))
a
.
append
(
Motion
BasicAnimation
.
scaleZ
(
to
:
to
))
case
let
.
translate
(
x
,
y
):
a
.
append
(
Motion
.
translate
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
a
.
append
(
Motion
BasicAnimation
.
translate
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
case
let
.
translateX
(
to
):
a
.
append
(
Motion
.
translateX
(
to
:
to
))
a
.
append
(
Motion
BasicAnimation
.
translateX
(
to
:
to
))
case
let
.
translateY
(
to
):
a
.
append
(
Motion
.
translateY
(
to
:
to
))
a
.
append
(
Motion
BasicAnimation
.
translateY
(
to
:
to
))
case
let
.
translateZ
(
to
):
a
.
append
(
Motion
.
translateZ
(
to
:
to
))
a
.
append
(
Motion
BasicAnimation
.
translateZ
(
to
:
to
))
case
.
x
(
_
),
.
y
(
_
),
.
point
(
_
,
_
):
let
position
=
Motion
.
position
(
to
:
CGPoint
(
x
:
px
,
y
:
py
))
let
position
=
Motion
BasicAnimation
.
position
(
to
:
CGPoint
(
x
:
px
,
y
:
py
))
a
.
append
(
position
)
case
let
.
position
(
x
,
y
):
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
a
.
append
(
Motion
BasicAnimation
.
position
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
case
let
.
fade
(
opacity
):
let
fade
=
Motion
.
fade
(
opacity
:
opacity
)
let
fade
=
Motion
BasicAnimation
.
fade
(
opacity
:
opacity
)
fade
.
fromValue
=
s
.
value
(
forKey
:
MotionAnimationKeyPath
.
opacity
.
rawValue
)
??
NSNumber
(
floatLiteral
:
1
)
a
.
append
(
fade
)
case
let
.
zPosition
(
index
):
let
zPosition
=
Motion
.
zPosition
(
index
:
index
)
let
zPosition
=
Motion
BasicAnimation
.
zPosition
(
index
:
index
)
zPosition
.
fromValue
=
s
.
value
(
forKey
:
MotionAnimationKeyPath
.
zPosition
.
rawValue
)
??
NSNumber
(
integerLiteral
:
0
)
a
.
append
(
zPosition
)
case
.
width
(
_
),
.
height
(
_
),
.
size
(
_
,
_
):
a
.
append
(
Motion
.
size
(
CGSize
(
width
:
w
,
height
:
h
)))
a
.
append
(
Motion
BasicAnimation
.
size
(
CGSize
(
width
:
w
,
height
:
h
)))
case
let
.
shadowPath
(
path
):
let
shadowPath
=
Motion
.
shadow
(
path
:
path
)
let
shadowPath
=
Motion
BasicAnimation
.
shadow
(
path
:
path
)
shadowPath
.
fromValue
=
s
.
shadowPath
a
.
append
(
shadowPath
)
case
let
.
shadowOffset
(
offset
):
let
shadowOffset
=
Motion
.
shadow
(
offset
:
offset
)
let
shadowOffset
=
Motion
BasicAnimation
.
shadow
(
offset
:
offset
)
shadowOffset
.
fromValue
=
s
.
shadowOffset
a
.
append
(
shadowOffset
)
case
let
.
shadowOpacity
(
opacity
):
let
shadowOpacity
=
Motion
.
shadow
(
opacity
:
opacity
)
let
shadowOpacity
=
Motion
BasicAnimation
.
shadow
(
opacity
:
opacity
)
shadowOpacity
.
fromValue
=
s
.
shadowOpacity
a
.
append
(
shadowOpacity
)
case
let
.
shadowRadius
(
radius
):
let
shadowRadius
=
Motion
.
shadow
(
radius
:
radius
)
let
shadowRadius
=
Motion
BasicAnimation
.
shadow
(
radius
:
radius
)
shadowRadius
.
fromValue
=
s
.
shadowRadius
a
.
append
(
shadowRadius
)
case
let
.
depth
(
offset
,
opacity
,
radius
):
if
let
path
=
s
.
shadowPath
{
let
shadowPath
=
Motion
.
shadow
(
path
:
path
)
let
shadowPath
=
Motion
BasicAnimation
.
shadow
(
path
:
path
)
shadowPath
.
fromValue
=
s
.
shadowPath
a
.
append
(
shadowPath
)
}
let
shadowOffset
=
Motion
.
shadow
(
offset
:
offset
)
let
shadowOffset
=
Motion
BasicAnimation
.
shadow
(
offset
:
offset
)
shadowOffset
.
fromValue
=
s
.
shadowOffset
a
.
append
(
shadowOffset
)
let
shadowOpacity
=
Motion
.
shadow
(
opacity
:
opacity
)
let
shadowOpacity
=
Motion
BasicAnimation
.
shadow
(
opacity
:
opacity
)
shadowOpacity
.
fromValue
=
s
.
shadowOpacity
a
.
append
(
shadowOpacity
)
let
shadowRadius
=
Motion
.
shadow
(
radius
:
radius
)
let
shadowRadius
=
Motion
BasicAnimation
.
shadow
(
radius
:
radius
)
shadowRadius
.
fromValue
=
s
.
shadowRadius
a
.
append
(
shadowRadius
)
default
:
break
...
...
@@ -462,7 +462,30 @@ extension CABasicAnimation {
}
}
extension
Motion
{
extension
CAKeyframeAnimation
{
/**
A convenience initializer that takes a given MotionAnimationKeyPath.
- Parameter keyPath: An MotionAnimationKeyPath.
*/
public
convenience
init
(
keyPath
:
MotionAnimationKeyPath
)
{
self
.
init
(
keyPath
:
keyPath
.
rawValue
)
}
}
public
struct
MotionKeyframeAnimation
{
/**
Creates a CABasicAnimation for the backgroundColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
public
static
func
background
(
color
:
UIColor
)
->
CAKeyframeAnimation
{
let
animation
=
CAKeyframeAnimation
(
keyPath
:
.
backgroundColor
)
animation
.
values
=
[
color
.
cgColor
]
return
animation
}
}
public
struct
MotionBasicAnimation
{
/**
Creates a CABasicAnimation for the backgroundColor key path.
- Parameter color: A UIColor.
...
...
Sources/iOS/PageMenuController.swift
View file @
ae0a2079
...
...
@@ -110,6 +110,7 @@ open class PageMenuController: UIViewController {
}
prepareViewControllers
()
prepareTabBar
()
layoutSubviews
()
}
}
...
...
@@ -133,7 +134,11 @@ open class PageMenuController: UIViewController {
fileprivate
var
previousContentOffset
:
CGFloat
=
0
/// The number of views used in the scrollViewPool.
fileprivate
let
viewPoolCount
=
3
open
var
viewPoolCount
=
3
{
didSet
{
layoutSubviews
()
}
}
/**
An initializer that accepts an Array of UIViewControllers.
...
...
@@ -177,6 +182,7 @@ open class PageMenuController: UIViewController {
view
.
contentScaleFactor
=
Screen
.
scale
prepareScrollView
()
prepareViewControllers
()
prepareTabBar
()
}
}
...
...
@@ -218,8 +224,6 @@ extension PageMenuController {
prepareViewController
(
at
:
selectedIndex
-
1
)
prepareViewController
(
at
:
selectedIndex
+
1
)
}
prepareTabBar
()
}
/**
...
...
@@ -284,19 +288,32 @@ extension PageMenuController {
vc
.
view
.
contentScaleFactor
=
Screen
.
scale
scrollView
.
addSubview
(
vc
.
view
)
}
/**
Transitions from one view controller to another.
- Parameter from: The index of the view controller to transition from.
- Parameter to: The index of the view controller to transition to.
*/
fileprivate
func
prepareViewControllersForTransition
(
from
:
Int
,
to
:
Int
)
{
let
fromVC
=
viewControllers
[
from
]
let
toVC
=
viewControllers
[
to
]
fromVC
.
present
(
toVC
,
animated
:
true
)
}
}
extension
PageMenuController
{
fileprivate
func
layoutScrollView
()
{
scrollView
.
contentSize
=
CGSize
(
width
:
scrollView
.
width
*
CGFloat
(
viewControllers
.
count
),
height
:
scrollView
.
height
)
scrollView
.
contentOffset
=
CGPoint
(
x
:
scrollView
.
width
*
CGFloat
(
selectedIndex
),
y
:
0
)
let
w
=
view
.
bounds
.
width
scrollView
.
contentSize
=
CGSize
(
width
:
w
*
CGFloat
(
viewControllers
.
count
),
height
:
scrollView
.
height
)
scrollView
.
contentOffset
=
CGPoint
(
x
:
w
*
CGFloat
(
selectedIndex
),
y
:
0
)
guard
let
v
=
tabBar
else
{
scrollView
.
frame
=
view
.
bounds
return
}
let
p
=
tabBar
?
.
height
??
0
let
p
=
v
.
height
let
y
=
view
.
height
-
p
switch
tabBarAlignment
{
...
...
@@ -310,6 +327,8 @@ extension PageMenuController {
scrollView
.
y
=
0
scrollView
.
height
=
view
.
height
}
scrollView
.
width
=
w
}
fileprivate
func
layoutViewControllers
()
{
...
...
@@ -344,7 +363,8 @@ extension PageMenuController {
- Parameter position: An Int for the position of the view controller.
*/
fileprivate
func
layoutViewController
(
at
index
:
Int
,
position
:
Int
)
{
viewControllers
[
index
]
.
view
.
frame
=
CGRect
(
x
:
CGFloat
(
position
)
*
scrollView
.
width
,
y
:
0
,
width
:
scrollView
.
width
,
height
:
scrollView
.
height
)
let
w
=
scrollView
.
width
viewControllers
[
index
]
.
view
.
frame
=
CGRect
(
x
:
CGFloat
(
position
)
*
w
,
y
:
0
,
width
:
w
,
height
:
scrollView
.
height
)
}
/**
...
...
@@ -355,20 +375,20 @@ extension PageMenuController {
return
}
let
p
=
tabBar
?
.
height
??
0
let
p
=
v
.
height
let
y
=
view
.
height
-
p
tabBar
?
.
width
=
view
.
width
v
.
width
=
view
.
width
switch
tabBarAlignment
{
case
.
top
:
tabBar
?
.
isHidden
=
false
tabBar
?
.
y
=
0
v
.
isHidden
=
false
v
.
y
=
0
case
.
bottom
:
tabBar
?
.
isHidden
=
false
tabBar
?
.
y
=
y
v
.
isHidden
=
false
v
.
y
=
y
case
.
hidden
:
tabBar
?
.
isHidden
=
true
v
.
isHidden
=
true
}
}
}
...
...
@@ -411,13 +431,13 @@ extension PageMenuController {
- Parameter at index: An Int for the view controller position.
*/
fileprivate
func
removeViewController
(
at
index
:
Int
)
{
let
v
c
=
viewControllers
[
index
]
let
v
=
viewControllers
[
index
]
guard
childViewControllers
.
contains
(
v
c
)
else
{
guard
childViewControllers
.
contains
(
v
)
else
{
return
}
removeViewController
(
viewController
:
v
c
)
removeViewController
(
viewController
:
v
)
}
/**
...
...
@@ -450,12 +470,15 @@ extension PageMenuController {
return
}
removeViewControllers
()
prepareViewControllersForTransition
(
from
:
selectedIndex
,
to
:
i
)
selectedIndex
=
i
v
.
select
(
at
:
i
)
removeViewControllers
()
prepareViewControllers
()
layoutSubviews
()
//prepareTabBar()
//layoutSubviews()
}
}
...
...
@@ -469,6 +492,7 @@ extension PageMenuController: UIScrollViewDelegate {
removeViewControllers
()
prepareViewControllers
()
prepareTabBar
()
layoutSubviews
()
}
}
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