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
3983101e
Unverified
Commit
3983101e
authored
Jan 23, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: working MaterialTransition for both present and dismiss
parent
2e56fcd5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
52 deletions
+111
-52
Sources/iOS/MotionTransition.swift
+111
-52
No files found.
Sources/iOS/MotionTransition.swift
View file @
3983101e
...
...
@@ -133,8 +133,7 @@ extension UIView {
contentView
.
masksToBounds
=
true
v
.
motionTransitionIdentifier
=
view
.
motionTransitionIdentifier
v
.
position
=
view
.
superview
?
.
convert
(
view
.
position
,
to
:
nil
)
??
view
.
position
v
.
bounds
=
view
.
bounds
v
.
frame
=
convert
(
view
.
bounds
,
from
:
view
)
v
.
cornerRadius
=
view
.
cornerRadius
v
.
zPosition
=
view
.
zPosition
v
.
opacity
=
view
.
opacity
...
...
@@ -317,17 +316,22 @@ open class MotionTransitionPresentedAnimator: MotionTransitionAnimator {
super
.
animateTransition
(
using
:
transitionContext
)
let
bgView
=
UIView
()
bgView
.
backgroundColor
=
.
clea
r
bgView
.
backgroundColor
=
fromViewController
.
view
.
backgroundColo
r
bgView
.
frame
=
transitionView
.
bounds
transitionView
.
addSubview
(
bgView
)
containerView
.
insertSubview
(
toViewController
.
view
,
belowSubview
:
transitionView
)
toViewController
.
view
.
updateConstraints
()
toViewController
.
view
.
setNeedsLayout
()
toViewController
.
view
.
layoutIfNeeded
()
for
toView
in
toViews
{
for
fromView
in
fromViews
{
if
toView
.
motionTransitionIdentifier
==
fromView
.
motionTransitionIdentifier
{
var
t
:
TimeInterval
=
0
var
d
:
TimeInterval
=
0
var
a
=
[
CABasicAnimation
]()
var
snapshotAnimations
=
[
CABasicAnimation
]()
var
snapshotChildAnimations
=
[
CABasicAnimation
]()
var
tf
=
MotionAnimationTimingFunction
.
easeInEaseOut
for
ta
in
toView
.
motionTransitionAnimations
{
...
...
@@ -346,19 +350,24 @@ open class MotionTransitionPresentedAnimator: MotionTransitionAnimator {
}
}
var
w
:
CGFloat
=
toView
.
bounds
.
width
var
h
:
CGFloat
=
toView
.
bounds
.
height
var
px
:
CGFloat
=
toView
.
position
.
x
+
w
/
2
var
py
:
CGFloat
=
toView
.
position
.
y
+
h
/
2
a
.
append
(
Motion
.
position
(
x
:
px
,
y
:
py
))
a
.
append
(
Motion
.
size
(
CGSize
(
width
:
w
,
height
:
h
)))
let
b
=
toView
.
superview
?
.
convert
(
toView
.
bounds
,
from
:
toView
)
??
toView
.
bounds
let
w
=
b
.
width
let
h
=
b
.
height
let
p
=
toView
.
superview
?
.
convert
(
toView
.
position
,
to
:
nil
)
??
toView
.
position
snapshotAnimations
.
append
(
Motion
.
position
(
x
:
p
.
x
,
y
:
p
.
y
))
let
sizeAnimation
=
Motion
.
size
(
CGSize
(
width
:
w
,
height
:
h
))
snapshotAnimations
.
append
(
sizeAnimation
)
let
rotate
=
Motion
.
rotate
(
angle
:
toView
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
as?
CGFloat
??
0
)
rotate
.
fromValue
=
fromView
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
a
.
append
(
rotate
)
snapshotChildAnimations
.
append
(
Motion
.
position
(
x
:
w
/
2
,
y
:
h
/
2
))
snapshotChildAnimations
.
append
(
sizeAnimation
)
a
.
append
(
Motion
.
background
(
color
:
toView
.
backgroundColor
??
.
clear
))
a
.
append
(
Motion
.
corner
(
radius
:
toView
.
cornerRadius
))
let
rotateAnimation
=
Motion
.
rotate
(
angle
:
toView
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
as?
CGFloat
??
0
)
rotateAnimation
.
fromValue
=
fromView
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
snapshotAnimations
.
append
(
rotateAnimation
)
snapshotChildAnimations
.
append
(
Motion
.
background
(
color
:
toView
.
backgroundColor
??
.
clear
))
snapshotChildAnimations
.
append
(
Motion
.
corner
(
radius
:
toView
.
cornerRadius
))
let
snapshot
=
transitionView
.
snapshot
(
view
:
fromView
,
afterUpdates
:
true
)
...
...
@@ -368,18 +377,23 @@ open class MotionTransitionPresentedAnimator: MotionTransitionAnimator {
case
let
.
timingFunction
(
timingFunction
):
tf
=
timingFunction
case
let
.
shadow
(
path
):
a
.
append
(
Motion
.
shadow
(
path
:
path
))
snapshotAnimations
.
append
(
Motion
.
shadow
(
path
:
path
))
default
:
break
}
}
let
g
=
Motion
.
animate
(
group
:
a
,
duration
:
d
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
g
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
tf
)
let
snapshotGroup
=
Motion
.
animate
(
group
:
snapshotAnimations
,
duration
:
d
)
snapshotGroup
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
snapshotGroup
.
isRemovedOnCompletion
=
false
snapshotGroup
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
tf
)
let
snapshotChildGroup
=
Motion
.
animate
(
group
:
snapshotChildAnimations
,
duration
:
d
)
snapshotChildGroup
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
snapshotChildGroup
.
isRemovedOnCompletion
=
false
snapshotChildGroup
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
tf
)
snapshot
.
animate
(
g
)
snapshot
.
subviews
.
first
!.
animate
(
g
)
snapshot
.
animate
(
snapshotGroup
)
snapshot
.
subviews
.
first
!.
animate
(
snapshotChildGroup
)
}
}
}
...
...
@@ -400,7 +414,6 @@ open class MotionTransitionPresentedAnimator: MotionTransitionAnimator {
return
}
s
.
containerView
.
addSubview
(
s
.
toViewController
.
view
)
s
.
transitionView
.
removeFromSuperview
()
for
v
in
s
.
transitionView
.
subviews
{
v
.
removeFromSuperview
()
...
...
@@ -414,16 +427,21 @@ open class MotionTransitionDismissedAnimator: MotionTransitionAnimator {
open
override
func
animateTransition
(
using
transitionContext
:
UIViewControllerContextTransitioning
)
{
super
.
animateTransition
(
using
:
transitionContext
)
for
v
in
fromViews
{
for
v2
in
toViews
{
if
v
.
motionTransitionIdentifier
==
v2
.
motionTransitionIdentifier
{
let
bgView
=
UIView
()
bgView
.
backgroundColor
=
fromViewController
.
view
.
backgroundColor
bgView
.
frame
=
transitionView
.
bounds
transitionView
.
addSubview
(
bgView
)
for
toView
in
toViews
{
for
fromView
in
fromViews
{
if
toView
.
motionTransitionIdentifier
==
fromView
.
motionTransitionIdentifier
{
var
t
:
TimeInterval
=
0
var
d
:
TimeInterval
=
0
var
a
=
[
CABasicAnimation
]()
var
snapshotAnimations
=
[
CABasicAnimation
]()
var
snapshotChildAnimations
=
[
CABasicAnimation
]()
var
tf
=
MotionAnimationTimingFunction
.
easeInEaseOut
for
ta
in
v
.
motionTransitionAnimations
{
for
ta
in
toView
.
motionTransitionAnimations
{
switch
ta
{
case
let
.
delay
(
time
):
if
time
>
delay
{
...
...
@@ -435,44 +453,85 @@ open class MotionTransitionDismissedAnimator: MotionTransitionAnimator {
duration
=
time
}
d
=
time
default
:
break
}
}
let
b
=
toView
.
superview
?
.
convert
(
toView
.
bounds
,
from
:
toView
)
??
toView
.
bounds
let
w
=
b
.
width
let
h
=
b
.
height
let
p
=
toView
.
superview
?
.
convert
(
toView
.
position
,
to
:
nil
)
??
toView
.
position
snapshotAnimations
.
append
(
Motion
.
position
(
x
:
p
.
x
,
y
:
p
.
y
))
let
sizeAnimation
=
Motion
.
size
(
CGSize
(
width
:
w
,
height
:
h
))
snapshotAnimations
.
append
(
sizeAnimation
)
snapshotChildAnimations
.
append
(
Motion
.
position
(
x
:
w
/
2
,
y
:
h
/
2
))
snapshotChildAnimations
.
append
(
sizeAnimation
)
let
rotateAnimation
=
Motion
.
rotate
(
angle
:
toView
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
as?
CGFloat
??
0
)
rotateAnimation
.
fromValue
=
fromView
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
snapshotAnimations
.
append
(
rotateAnimation
)
snapshotChildAnimations
.
append
(
Motion
.
background
(
color
:
toView
.
backgroundColor
??
.
clear
))
snapshotChildAnimations
.
append
(
Motion
.
corner
(
radius
:
toView
.
cornerRadius
))
let
snapshot
=
transitionView
.
snapshot
(
view
:
fromView
,
afterUpdates
:
true
)
Motion
.
delay
(
t
)
{
for
ta
in
toView
.
motionTransitionAnimations
{
switch
ta
{
case
let
.
timingFunction
(
timingFunction
):
tf
=
timingFunction
case
.
rotate
(
_
):
let
radians
=
CGFloat
(
atan2f
(
Float
(
v2
.
transform
.
b
),
Float
(
v2
.
transform
.
a
)))
let
rotate
=
Motion
.
rotate
(
angle
:
radians
*
180
/
CGFloat
(
M_PI
))
rotate
.
fromValue
=
v
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
a
.
append
(
rotate
)
case
.
backgroundColor
(
_
):
a
.
append
(
Motion
.
background
(
color
:
.
clear
))
case
.
corners
(
_
):
a
.
append
(
Motion
.
corner
(
radius
:
v2
.
cornerRadius
))
case
.
x
(
_
),
.
y
(
_
),
.
point
(
_
,
_
),
.
position
(
_
,
_
):
a
.
append
(
Motion
.
position
(
to
:
nil
==
v2
.
superview
?
v2
.
position
:
v2
.
superview
!.
convert
(
v2
.
position
,
to
:
nil
)))
case
let
.
shadow
(
path
):
a
.
append
(
Motion
.
shadow
(
path
:
path
))
case
.
width
(
_
):
a
.
append
(
Motion
.
width
(
v2
.
bounds
.
width
))
case
.
height
(
_
):
a
.
append
(
Motion
.
height
(
v2
.
bounds
.
height
))
snapshotAnimations
.
append
(
Motion
.
shadow
(
path
:
path
))
default
:
break
}
}
Motion
.
delay
(
t
)
{
let
g
=
Motion
.
animate
(
group
:
a
,
duration
:
d
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
g
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
tf
)
let
snapshotGroup
=
Motion
.
animate
(
group
:
snapshotAnimations
,
duration
:
d
)
snapshotGroup
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
snapshotGroup
.
isRemovedOnCompletion
=
false
snapshotGroup
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
tf
)
v
.
animate
(
g
)
let
snapshotChildGroup
=
Motion
.
animate
(
group
:
snapshotChildAnimations
,
duration
:
d
)
snapshotChildGroup
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
snapshotChildGroup
.
isRemovedOnCompletion
=
false
snapshotChildGroup
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
tf
)
snapshot
.
animate
(
snapshotGroup
)
snapshot
.
subviews
.
first
!.
animate
(
snapshotChildGroup
)
}
}
}
}
fromViewController
.
view
.
isHidden
=
true
let
d
=
transitionDuration
(
using
:
transitionContext
)
if
nil
!=
bgView
.
backgroundColor
{
bgView
.
motion
(
.
backgroundColor
(
.
clear
),
.
duration
(
d
))
}
Motion
.
delay
(
delay
+
duration
)
{
Motion
.
delay
(
d
)
{
[
weak
self
]
in
defer
{
transitionContext
.
completeTransition
(
!
transitionContext
.
transitionWasCancelled
)
}
guard
let
s
=
self
else
{
return
}
for
v
in
s
.
toViews
{
v
.
isHidden
=
false
}
s
.
transitionView
.
removeFromSuperview
()
for
v
in
s
.
transitionView
.
subviews
{
v
.
removeFromSuperview
()
}
}
}
}
...
...
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