Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Motion
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
Motion
Commits
a9f73344
Unverified
Commit
a9f73344
authored
Feb 26, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added depth animation to Motion
parent
65c3210c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
33 deletions
+111
-33
Sources/Motion.swift
+24
-18
Sources/MotionAnimation.swift
+87
-15
No files found.
Sources/Motion.swift
View file @
a9f73344
...
...
@@ -243,9 +243,6 @@ extension UIView {
open
func
transitionSnapshot
(
afterUpdates
:
Bool
,
shouldHide
:
Bool
=
true
)
->
UIView
{
isHidden
=
false
// Material specific.
(
self
as?
PulseableLayer
)?
.
pulseLayer
?
.
isHidden
=
true
let
oldCornerRadius
=
layer
.
cornerRadius
layer
.
cornerRadius
=
0
...
...
@@ -291,9 +288,6 @@ extension UIView {
v
.
motionTransform
=
motionTransform
v
.
backgroundColor
=
backgroundColor
// Material specific.
(
self
as?
PulseableLayer
)?
.
pulseLayer
?
.
isHidden
=
false
isHidden
=
shouldHide
return
v
...
...
@@ -306,15 +300,10 @@ open class MotionPresentationController: UIPresentationController {
return
}
presentedViewController
.
transitionCoordinator
?
.
animate
(
alongsideTransition
:
{
(
context
)
in
print
(
"Animating"
)
})
print
(
"presentationTransitionWillBegin"
)
presentedViewController
.
transitionCoordinator
?
.
animate
(
alongsideTransition
:
{
(
context
)
in
})
}
open
override
func
presentationTransitionDidEnd
(
_
completed
:
Bool
)
{
print
(
"presentationTransitionDidEnd"
)
}
open
override
func
dismissalTransitionWillBegin
()
{
...
...
@@ -322,15 +311,10 @@ open class MotionPresentationController: UIPresentationController {
return
}
presentedViewController
.
transitionCoordinator
?
.
animate
(
alongsideTransition
:
{
(
context
)
in
print
(
"Animating"
)
})
print
(
"dismissalTransitionWillBegin"
)
presentedViewController
.
transitionCoordinator
?
.
animate
(
alongsideTransition
:
{
(
context
)
in
})
}
open
override
func
dismissalTransitionDidEnd
(
_
completed
:
Bool
)
{
print
(
"dismissalTransitionDidEnd"
)
}
open
override
var
frameOfPresentedViewInContainerView
:
CGRect
{
...
...
@@ -631,6 +615,28 @@ extension Motion {
snapshotAnimations
.
append
(
Motion
.
transform
(
transform
:
to
.
motionTransform
))
snapshotAnimations
.
append
(
Motion
.
background
(
color
:
to
.
backgroundColor
??
.
clear
))
if
let
v
=
to
.
shadowPath
{
snapshotAnimations
.
append
(
Motion
.
shadow
(
path
:
v
))
}
if
let
path
=
to
.
shadowPath
{
let
shadowPath
=
Motion
.
shadow
(
path
:
path
)
shadowPath
.
fromValue
=
fromView
.
shadowPath
snapshotAnimations
.
append
(
shadowPath
)
}
let
shadowOffset
=
Motion
.
shadow
(
offset
:
to
.
shadowOffset
)
shadowOffset
.
fromValue
=
fromView
.
shadowOffset
snapshotAnimations
.
append
(
shadowOffset
)
let
shadowOpacity
=
Motion
.
shadow
(
opacity
:
to
.
shadowOpacity
)
shadowOpacity
.
fromValue
=
fromView
.
shadowOpacity
snapshotAnimations
.
append
(
shadowOpacity
)
let
shadowRadius
=
Motion
.
shadow
(
radius
:
to
.
shadowRadius
)
shadowRadius
.
fromValue
=
fromView
.
shadowRadius
snapshotAnimations
.
append
(
shadowRadius
)
snapshotChildAnimations
.
append
(
cornerRadiusAnimation
)
snapshotChildAnimations
.
append
(
sizeAnimation
)
snapshotChildAnimations
.
append
(
Motion
.
position
(
x
:
to
.
bounds
.
width
/
2
,
y
:
to
.
bounds
.
height
/
2
))
...
...
Sources/MotionAnimation.swift
View file @
a9f73344
...
...
@@ -48,12 +48,15 @@ public enum MotionAnimationKeyPath: String {
case
translationY
=
"transform.translation.y"
case
translationZ
=
"transform.translation.z"
case
position
case
shadowPath
case
opacity
case
zPosition
case
width
=
"bounds.size.width"
case
height
=
"bounds.size.height"
case
size
=
"bounds.size"
case
shadowPath
case
shadowOffset
case
shadowOpacity
case
shadowRadius
}
public
enum
MotionAnimation
{
...
...
@@ -85,12 +88,16 @@ public enum MotionAnimation {
case
y
(
CGFloat
)
case
point
(
x
:
CGFloat
,
y
:
CGFloat
)
case
position
(
x
:
CGFloat
,
y
:
CGFloat
)
case
shadow
(
path
:
CGPath
)
case
fade
(
Double
)
case
zPosition
(
Int
)
case
width
(
CGFloat
)
case
height
(
CGFloat
)
case
size
(
width
:
CGFloat
,
height
:
CGFloat
)
case
shadowPath
(
CGPath
)
case
shadowOffset
(
CGSize
)
case
shadowOpacity
(
Float
)
case
shadowRadius
(
CGFloat
)
case
depth
(
shadowOffset
:
CGSize
,
shadowOpacity
:
Float
,
shadowRadius
:
CGFloat
)
}
@available(iOS 10, *)
...
...
@@ -299,8 +306,6 @@ extension CALayer {
a
.
append
(
position
)
case
let
.
position
(
x
,
y
):
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
case
let
.
shadow
(
path
):
a
.
append
(
Motion
.
shadow
(
path
:
path
))
case
let
.
fade
(
opacity
):
let
fade
=
Motion
.
fade
(
opacity
:
opacity
)
fade
.
fromValue
=
s
.
value
(
forKey
:
MotionAnimationKeyPath
.
opacity
.
rawValue
)
??
NSNumber
(
floatLiteral
:
1
)
...
...
@@ -311,6 +316,40 @@ extension CALayer {
a
.
append
(
zPosition
)
case
.
width
(
_
),
.
height
(
_
),
.
size
(
_
,
_
):
a
.
append
(
Motion
.
size
(
CGSize
(
width
:
w
,
height
:
h
)))
case
let
.
shadowPath
(
path
):
let
shadowPath
=
Motion
.
shadow
(
path
:
path
)
shadowPath
.
fromValue
=
s
.
shadowPath
a
.
append
(
shadowPath
)
case
let
.
shadowOffset
(
offset
):
let
shadowOffset
=
Motion
.
shadow
(
offset
:
offset
)
shadowOffset
.
fromValue
=
s
.
shadowOffset
a
.
append
(
shadowOffset
)
case
let
.
shadowOpacity
(
opacity
):
let
shadowOpacity
=
Motion
.
shadow
(
opacity
:
opacity
)
shadowOpacity
.
fromValue
=
s
.
shadowOpacity
a
.
append
(
shadowOpacity
)
case
let
.
shadowRadius
(
radius
):
let
shadowRadius
=
Motion
.
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
)
shadowPath
.
fromValue
=
s
.
shadowPath
a
.
append
(
shadowPath
)
}
let
shadowOffset
=
Motion
.
shadow
(
offset
:
offset
)
shadowOffset
.
fromValue
=
s
.
shadowOffset
a
.
append
(
shadowOffset
)
let
shadowOpacity
=
Motion
.
shadow
(
opacity
:
opacity
)
shadowOpacity
.
fromValue
=
s
.
shadowOpacity
a
.
append
(
shadowOpacity
)
let
shadowRadius
=
Motion
.
shadow
(
radius
:
radius
)
shadowRadius
.
fromValue
=
s
.
shadowRadius
a
.
append
(
shadowRadius
)
default
:
break
}
}
...
...
@@ -660,17 +699,6 @@ extension Motion {
}
/**
Creates a CABasicAnimation for the shadowPath key path.
- Parameter path: A CGPath.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
path
:
CGPath
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowPath
)
animation
.
toValue
=
path
return
animation
}
/**
Creates a CABasicAnimation for the opacity key path.
- Parameter opacity: A Double.
- Returns: A CABasicAnimation.
...
...
@@ -724,4 +752,48 @@ extension Motion {
animation
.
toValue
=
NSValue
(
cgSize
:
size
)
return
animation
}
/**
Creates a CABasicAnimation for the shadowPath key path.
- Parameter path: A CGPath.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
path
:
CGPath
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowPath
)
animation
.
toValue
=
path
return
animation
}
/**
Creates a CABasicAnimation for the shadowOffset key path.
- Parameter offset: CGSize.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
offset
:
CGSize
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowOffset
)
animation
.
toValue
=
NSValue
(
cgSize
:
offset
)
return
animation
}
/**
Creates a CABasicAnimation for the shadowOpacity key path.
- Parameter opacity: Float.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
opacity
:
Float
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowOpacity
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
opacity
))
return
animation
}
/**
Creates a CABasicAnimation for the shadowRadius key path.
- Parameter radius: CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
radius
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowRadius
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
radius
))
return
animation
}
}
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