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
19e673bf
Unverified
Commit
19e673bf
authored
Jun 09, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
partial rework to MotionTransition and its relating parts
parent
06ec8deb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
216 additions
and
223 deletions
+216
-223
Motion.xcodeproj/project.pbxproj
+0
-4
Sources/Debug Plugin/MotionDebugPlugin.swift
+3
-3
Sources/Debug Plugin/MotionDebugView.swift
+10
-10
Sources/DefaultAnimationPreprocessor.swift
+46
-39
Sources/Extensions/Motion+CALayer.swift
+16
-16
Sources/Extensions/Motion+UIKit.swift
+1
-1
Sources/Extensions/Motion+UIView.swift
+1
-1
Sources/MotionAnimation.swift
+40
-40
Sources/MotionPlugin.swift
+7
-7
Sources/MotionTargetState.swift
+1
-1
Sources/MotionTransition+MotionStringConvertible.swift
+7
-7
Sources/MotionTransition.swift
+0
-0
Sources/Preprocessors/BasePreprocessor.swift
+0
-34
Sources/Preprocessors/CascadePreprocessor.swift
+5
-2
Sources/Preprocessors/DurationPreprocessor.swift
+16
-9
Sources/Preprocessors/IgnoreSubviewModifiersPreprocessor.swift
+5
-2
Sources/Preprocessors/MatchPreprocessor.swift
+51
-43
Sources/Preprocessors/SourcePreprocessor.swift
+7
-4
No files found.
Motion.xcodeproj/project.pbxproj
View file @
19e673bf
...
@@ -42,7 +42,6 @@
...
@@ -42,7 +42,6 @@
96AEB6A81EE4610F009A3BE0
/* Nodes.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6831EE4610F009A3BE0
/* Nodes.swift */
;
};
96AEB6A81EE4610F009A3BE0
/* Nodes.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6831EE4610F009A3BE0
/* Nodes.swift */
;
};
96AEB6A91EE4610F009A3BE0
/* Parser.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6841EE4610F009A3BE0
/* Parser.swift */
;
};
96AEB6A91EE4610F009A3BE0
/* Parser.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6841EE4610F009A3BE0
/* Parser.swift */
;
};
96AEB6AA1EE4610F009A3BE0
/* Regex.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6851EE4610F009A3BE0
/* Regex.swift */
;
};
96AEB6AA1EE4610F009A3BE0
/* Regex.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6851EE4610F009A3BE0
/* Regex.swift */
;
};
96AEB6AB1EE4610F009A3BE0
/* BasePreprocessor.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6871EE4610F009A3BE0
/* BasePreprocessor.swift */
;
};
96AEB6AC1EE4610F009A3BE0
/* CascadePreprocessor.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6881EE4610F009A3BE0
/* CascadePreprocessor.swift */
;
};
96AEB6AC1EE4610F009A3BE0
/* CascadePreprocessor.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6881EE4610F009A3BE0
/* CascadePreprocessor.swift */
;
};
96AEB6AD1EE4610F009A3BE0
/* DurationPreprocessor.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6891EE4610F009A3BE0
/* DurationPreprocessor.swift */
;
};
96AEB6AD1EE4610F009A3BE0
/* DurationPreprocessor.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB6891EE4610F009A3BE0
/* DurationPreprocessor.swift */
;
};
96AEB6AE1EE4610F009A3BE0
/* IgnoreSubviewModifiersPreprocessor.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB68A1EE4610F009A3BE0
/* IgnoreSubviewModifiersPreprocessor.swift */
;
};
96AEB6AE1EE4610F009A3BE0
/* IgnoreSubviewModifiersPreprocessor.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB68A1EE4610F009A3BE0
/* IgnoreSubviewModifiersPreprocessor.swift */
;
};
...
@@ -86,7 +85,6 @@
...
@@ -86,7 +85,6 @@
96AEB6831EE4610F009A3BE0
/* Nodes.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Nodes.swift
;
sourceTree
=
"<group>"
;
};
96AEB6831EE4610F009A3BE0
/* Nodes.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Nodes.swift
;
sourceTree
=
"<group>"
;
};
96AEB6841EE4610F009A3BE0
/* Parser.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Parser.swift
;
sourceTree
=
"<group>"
;
};
96AEB6841EE4610F009A3BE0
/* Parser.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Parser.swift
;
sourceTree
=
"<group>"
;
};
96AEB6851EE4610F009A3BE0
/* Regex.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Regex.swift
;
sourceTree
=
"<group>"
;
};
96AEB6851EE4610F009A3BE0
/* Regex.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Regex.swift
;
sourceTree
=
"<group>"
;
};
96AEB6871EE4610F009A3BE0
/* BasePreprocessor.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
BasePreprocessor.swift
;
sourceTree
=
"<group>"
;
};
96AEB6881EE4610F009A3BE0
/* CascadePreprocessor.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CascadePreprocessor.swift
;
sourceTree
=
"<group>"
;
};
96AEB6881EE4610F009A3BE0
/* CascadePreprocessor.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
CascadePreprocessor.swift
;
sourceTree
=
"<group>"
;
};
96AEB6891EE4610F009A3BE0
/* DurationPreprocessor.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
DurationPreprocessor.swift
;
sourceTree
=
"<group>"
;
};
96AEB6891EE4610F009A3BE0
/* DurationPreprocessor.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
DurationPreprocessor.swift
;
sourceTree
=
"<group>"
;
};
96AEB68A1EE4610F009A3BE0
/* IgnoreSubviewModifiersPreprocessor.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
IgnoreSubviewModifiersPreprocessor.swift
;
sourceTree
=
"<group>"
;
};
96AEB68A1EE4610F009A3BE0
/* IgnoreSubviewModifiersPreprocessor.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
IgnoreSubviewModifiersPreprocessor.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -163,7 +161,6 @@
...
@@ -163,7 +161,6 @@
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
968989DB1EE65F2B003B8F3D
/* MotionPreprocessor.swift */
,
968989DB1EE65F2B003B8F3D
/* MotionPreprocessor.swift */
,
96AEB6871EE4610F009A3BE0
/* BasePreprocessor.swift */
,
96AEB6881EE4610F009A3BE0
/* CascadePreprocessor.swift */
,
96AEB6881EE4610F009A3BE0
/* CascadePreprocessor.swift */
,
96AEB6891EE4610F009A3BE0
/* DurationPreprocessor.swift */
,
96AEB6891EE4610F009A3BE0
/* DurationPreprocessor.swift */
,
96AEB68A1EE4610F009A3BE0
/* IgnoreSubviewModifiersPreprocessor.swift */
,
96AEB68A1EE4610F009A3BE0
/* IgnoreSubviewModifiersPreprocessor.swift */
,
...
@@ -335,7 +332,6 @@
...
@@ -335,7 +332,6 @@
96AEB69E1EE4610F009A3BE0
/* MotionController.swift in Sources */
,
96AEB69E1EE4610F009A3BE0
/* MotionController.swift in Sources */
,
96AEB6A11EE4610F009A3BE0
/* MotionTransition.swift in Sources */
,
96AEB6A11EE4610F009A3BE0
/* MotionTransition.swift in Sources */
,
96AEB6971EE4610F009A3BE0
/* Motion+CG.swift in Sources */
,
96AEB6971EE4610F009A3BE0
/* Motion+CG.swift in Sources */
,
96AEB6AB1EE4610F009A3BE0
/* BasePreprocessor.swift in Sources */
,
963150DA1EE51EB4002B0D42
/* MotionAnimationFillMode.swift in Sources */
,
963150DA1EE51EB4002B0D42
/* MotionAnimationFillMode.swift in Sources */
,
96AEB6AC1EE4610F009A3BE0
/* CascadePreprocessor.swift in Sources */
,
96AEB6AC1EE4610F009A3BE0
/* CascadePreprocessor.swift in Sources */
,
);
);
...
...
Sources/Debug Plugin/MotionDebugPlugin.swift
View file @
19e673bf
...
@@ -94,12 +94,12 @@ extension MotionDebugPlugin:MotionDebugViewDelegate {
...
@@ -94,12 +94,12 @@ extension MotionDebugPlugin:MotionDebugViewDelegate {
Motion
.
shared
.
update
(
elapsedTime
:
Double
(
seekValue
))
Motion
.
shared
.
update
(
elapsedTime
:
Double
(
seekValue
))
}
}
func
onPerspectiveChanged
(
translation
:
CGPoint
,
rotat
ion
:
CGFloat
,
scale
:
CGFloat
)
{
func
onPerspectiveChanged
(
translation
:
CGPoint
,
rotat
e
:
CGFloat
,
scale
:
CGFloat
)
{
var
t
=
CATransform3DIdentity
var
t
=
CATransform3DIdentity
t
.
m34
=
-
1
/
4000
t
.
m34
=
-
1
/
4000
t
=
CATransform3DTranslate
(
t
,
translation
.
x
,
translation
.
y
,
0
)
t
=
CATransform3DTranslate
(
t
,
translation
.
x
,
translation
.
y
,
0
)
t
=
CATransform3DScale
(
t
,
scale
,
scale
,
1
)
t
=
CATransform3DScale
(
t
,
scale
,
scale
,
1
)
t
=
CATransform3DRotate
(
t
,
rotat
ion
,
0
,
1
,
0
)
t
=
CATransform3DRotate
(
t
,
rotat
e
,
0
,
1
,
0
)
Motion
.
shared
.
container
.
layer
.
sublayerTransform
=
t
Motion
.
shared
.
container
.
layer
.
sublayerTransform
=
t
}
}
...
@@ -160,7 +160,7 @@ extension MotionDebugPlugin:MotionDebugViewDelegate {
...
@@ -160,7 +160,7 @@ extension MotionDebugPlugin:MotionDebugViewDelegate {
t
.
m34
=
-
1
/
4000
t
.
m34
=
-
1
/
4000
t
=
CATransform3DTranslate
(
t
,
debugView
!.
translation
.
x
,
debugView
!.
translation
.
y
,
0
)
t
=
CATransform3DTranslate
(
t
,
debugView
!.
translation
.
x
,
debugView
!.
translation
.
y
,
0
)
t
=
CATransform3DScale
(
t
,
debugView
!.
scale
,
debugView
!.
scale
,
1
)
t
=
CATransform3DScale
(
t
,
debugView
!.
scale
,
debugView
!.
scale
,
1
)
t
=
CATransform3DRotate
(
t
,
debugView
!.
rotat
ion
,
0
,
1
,
0
)
t
=
CATransform3DRotate
(
t
,
debugView
!.
rotat
e
,
0
,
1
,
0
)
}
else
{
}
else
{
for
v
in
Motion
.
shared
.
container
.
subviews
{
for
v
in
Motion
.
shared
.
container
.
subviews
{
animateZPosition
(
view
:
v
,
to
:
self
.
zPositionMap
[
v
]
??
0
)
animateZPosition
(
view
:
v
,
to
:
self
.
zPositionMap
[
v
]
??
0
)
...
...
Sources/Debug Plugin/MotionDebugView.swift
View file @
19e673bf
...
@@ -31,7 +31,7 @@ import UIKit
...
@@ -31,7 +31,7 @@ import UIKit
#if os(iOS)
#if os(iOS)
protocol
MotionDebugViewDelegate
:
class
{
protocol
MotionDebugViewDelegate
:
class
{
func
onProcessSliderChanged
(
progress
:
Float
)
func
onProcessSliderChanged
(
progress
:
Float
)
func
onPerspectiveChanged
(
translation
:
CGPoint
,
rotat
ion
:
CGFloat
,
scale
:
CGFloat
)
func
onPerspectiveChanged
(
translation
:
CGPoint
,
rotat
e
:
CGFloat
,
scale
:
CGFloat
)
func
on3D
(
wants3D
:
Bool
)
func
on3D
(
wants3D
:
Bool
)
func
onDisplayArcCurve
(
wantsCurve
:
Bool
)
func
onDisplayArcCurve
(
wantsCurve
:
Bool
)
func
onDone
()
func
onDone
()
...
@@ -56,7 +56,7 @@ class MotionDebugView: UIView {
...
@@ -56,7 +56,7 @@ class MotionDebugView: UIView {
}
}
var
showOnTop
:
Bool
=
false
var
showOnTop
:
Bool
=
false
var
rotat
ion
:
CGFloat
=
.
pi
/
6
var
rotat
e
:
CGFloat
=
.
pi
/
6
var
scale
:
CGFloat
=
0.6
var
scale
:
CGFloat
=
0.6
var
translation
:
CGPoint
=
.
zero
var
translation
:
CGPoint
=
.
zero
var
progress
:
Float
{
var
progress
:
Float
{
...
@@ -142,15 +142,15 @@ class MotionDebugView: UIView {
...
@@ -142,15 +142,15 @@ class MotionDebugView: UIView {
var
startRotation
:
CGFloat
=
0
var
startRotation
:
CGFloat
=
0
@objc
public
func
pan
()
{
@objc
public
func
pan
()
{
if
panGR
.
state
==
.
began
{
if
panGR
.
state
==
.
began
{
startRotation
=
rotat
ion
startRotation
=
rotat
e
}
}
rotat
ion
=
startRotation
+
panGR
.
translation
(
in
:
nil
)
.
x
/
150
rotat
e
=
startRotation
+
panGR
.
translation
(
in
:
nil
)
.
x
/
150
if
rotat
ion
>
.
pi
{
if
rotat
e
>
.
pi
{
rotat
ion
-=
2
*
.
pi
rotat
e
-=
2
*
.
pi
}
else
if
rotat
ion
<
-.
pi
{
}
else
if
rotat
e
<
-.
pi
{
rotat
ion
+=
2
*
.
pi
rotat
e
+=
2
*
.
pi
}
}
delegate
?
.
onPerspectiveChanged
(
translation
:
translation
,
rotat
ion
:
rotation
,
scale
:
scale
)
delegate
?
.
onPerspectiveChanged
(
translation
:
translation
,
rotat
e
:
rotate
,
scale
:
scale
)
}
}
var
startLocation
:
CGPoint
=
.
zero
var
startLocation
:
CGPoint
=
.
zero
...
@@ -167,7 +167,7 @@ class MotionDebugView: UIView {
...
@@ -167,7 +167,7 @@ class MotionDebugView: UIView {
if
pinchGR
.
numberOfTouches
>=
2
{
if
pinchGR
.
numberOfTouches
>=
2
{
scale
=
min
(
1
,
max
(
0.2
,
startScale
*
pinchGR
.
scale
))
scale
=
min
(
1
,
max
(
0.2
,
startScale
*
pinchGR
.
scale
))
translation
=
startTranslation
+
pinchGR
.
location
(
in
:
nil
)
-
startLocation
translation
=
startTranslation
+
pinchGR
.
location
(
in
:
nil
)
-
startLocation
delegate
?
.
onPerspectiveChanged
(
translation
:
translation
,
rotat
ion
:
rotation
,
scale
:
scale
)
delegate
?
.
onPerspectiveChanged
(
translation
:
translation
,
rotat
e
:
rotate
,
scale
:
scale
)
}
}
default
:
default
:
break
break
...
...
Sources/DefaultAnimationPreprocessor.swift
View file @
19e673bf
...
@@ -209,8 +209,10 @@ extension MotionDefaultAnimationType: MotionStringConvertible {
...
@@ -209,8 +209,10 @@ extension MotionDefaultAnimationType: MotionStringConvertible {
}
}
}
}
class
DefaultAnimationPreprocessor
:
BasePreprocessor
{
class
DefaultAnimationPreprocessor
:
MotionPreprocessor
{
/// A reference to a MotionContext.
weak
var
context
:
MotionContext
!
weak
var
motion
:
Motion
?
weak
var
motion
:
Motion
?
init
(
motion
:
Motion
)
{
init
(
motion
:
Motion
)
{
...
@@ -232,7 +234,12 @@ class DefaultAnimationPreprocessor: BasePreprocessor {
...
@@ -232,7 +234,12 @@ class DefaultAnimationPreprocessor: BasePreprocessor {
return
rtn
return
rtn
}
}
override
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
/**
Implementation for processor.
- Parameter fromViews: An Array of UIViews.
- Parameter toViews: An Array of UIViews.
*/
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
guard
let
motion
=
motion
else
{
return
}
guard
let
motion
=
motion
else
{
return
}
var
defaultAnimation
=
motion
.
defaultAnimation
var
defaultAnimation
=
motion
.
defaultAnimation
let
inNavigationController
=
motion
.
isNavigationController
let
inNavigationController
=
motion
.
isNavigationController
...
@@ -279,60 +286,60 @@ class DefaultAnimationPreprocessor: BasePreprocessor {
...
@@ -279,60 +286,60 @@ class DefaultAnimationPreprocessor: BasePreprocessor {
context
[
fromView
]
=
[
.
timingFunction
(
.
standard
),
.
duration
(
0.35
)]
context
[
fromView
]
=
[
.
timingFunction
(
.
standard
),
.
duration
(
0.35
)]
context
[
toView
]
=
[
.
timingFunction
(
.
standard
),
.
duration
(
0.35
)]
context
[
toView
]
=
[
.
timingFunction
(
.
standard
),
.
duration
(
0.35
)]
let
shadowState
:
[
MotionTransition
]
=
[
.
shadow
Opacity
(
0.5
),
let
shadowState
:
[
MotionTransition
]
=
[
.
shadow
(
opacity
:
0.5
),
.
shadowColor
(
.
black
),
.
shadow
(
color
:
.
black
),
.
shadowRadius
(
5
),
.
shadow
(
radius
:
5
),
.
shadowOffset
(
.
zero
),
.
shadow
(
offset
:
.
zero
),
.
masksToBounds
(
false
)]
.
masksToBounds
(
false
)]
switch
defaultAnimation
{
switch
defaultAnimation
{
case
.
push
(
let
direction
):
case
.
push
(
let
direction
):
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)),
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
shadowOpacity
(
0
),
.
shadow
(
opacity
:
0
),
.
beginWith
(
modifier
s
:
shadowState
),
.
beginWith
(
transition
s
:
shadowState
),
.
timingFunction
(
.
deceleration
)])
.
timingFunction
(
.
deceleration
)])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)
/
3
),
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)
/
3
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
timingFunction
(
.
deceleration
)])
.
timingFunction
(
.
deceleration
)])
case
.
pull
(
let
direction
):
case
.
pull
(
let
direction
):
motion
.
insertToViewFirst
=
true
motion
.
insertToViewFirst
=
true
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)),
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
shadow
Opacity
(
0
),
.
shadow
(
opacity
:
0
),
.
beginWith
(
modifier
s
:
shadowState
)])
.
beginWith
(
transition
s
:
shadowState
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)
/
3
),
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)
/
3
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
case
.
slide
(
let
direction
):
case
.
slide
(
let
direction
):
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
))])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
))])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
))])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
))])
case
.
zoomSlide
(
let
direction
):
case
.
zoomSlide
(
let
direction
):
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
scale
(
0.8
)])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
scale
(
to
:
0.8
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
scale
(
0.8
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
scale
(
to
:
0.8
)])
case
.
cover
(
let
direction
):
case
.
cover
(
let
direction
):
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)),
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
shadowOpacity
(
0
),
.
shadow
(
opacity
:
0
),
.
beginWith
(
modifier
s
:
shadowState
),
.
beginWith
(
transition
s
:
shadowState
),
.
timingFunction
(
.
deceleration
)])
.
timingFunction
(
.
deceleration
)])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
timingFunction
(
.
deceleration
)])
.
timingFunction
(
.
deceleration
)])
case
.
uncover
(
let
direction
):
case
.
uncover
(
let
direction
):
motion
.
insertToViewFirst
=
true
motion
.
insertToViewFirst
=
true
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)),
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
shadow
Opacity
(
0
),
.
shadow
(
opacity
:
0
),
.
beginWith
(
modifier
s
:
shadowState
)])
.
beginWith
(
transition
s
:
shadowState
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
case
.
pageIn
(
let
direction
):
case
.
pageIn
(
let
direction
):
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)),
context
[
toView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
shadow
Opacity
(
0
),
.
shadow
(
opacity
:
0
),
.
beginWith
(
modifier
s
:
shadowState
),
.
beginWith
(
transition
s
:
shadowState
),
.
timingFunction
(
.
deceleration
)])
.
timingFunction
(
.
deceleration
)])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
scale
(
0.7
),
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
timingFunction
(
.
deceleration
)])
.
timingFunction
(
.
deceleration
)])
case
.
pageOut
(
let
direction
):
case
.
pageOut
(
let
direction
):
motion
.
insertToViewFirst
=
true
motion
.
insertToViewFirst
=
true
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)),
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
shadow
Opacity
(
0
),
.
shadow
(
opacity
:
0
),
.
beginWith
(
modifier
s
:
shadowState
)])
.
beginWith
(
transition
s
:
shadowState
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
scale
(
0.7
),
context
[
toView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
case
.
fade
:
case
.
fade
:
// TODO: clean up this. overFullScreen logic shouldn't be here
// TODO: clean up this. overFullScreen logic shouldn't be here
...
@@ -348,15 +355,15 @@ class DefaultAnimationPreprocessor: BasePreprocessor {
...
@@ -348,15 +355,15 @@ class DefaultAnimationPreprocessor: BasePreprocessor {
}
}
#endif
#endif
context
[
toView
]
!.
append
(
.
durationMatch
Longest
)
context
[
toView
]
!.
append
(
.
preferredDurationMatches
Longest
)
context
[
fromView
]
!.
append
(
.
durationMatch
Longest
)
context
[
fromView
]
!.
append
(
.
preferredDurationMatches
Longest
)
case
.
zoom
:
case
.
zoom
:
motion
.
insertToViewFirst
=
true
motion
.
insertToViewFirst
=
true
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
scale
(
1.3
),
.
fade
])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
1.3
),
.
fade
])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
scale
(
0.7
)])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
)])
case
.
zoomOut
:
case
.
zoomOut
:
context
[
toView
]
!.
append
(
contentsOf
:
[
.
scale
(
1.3
),
.
fade
])
context
[
toView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
1.3
),
.
fade
])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
scale
(
0.7
)])
context
[
fromView
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
)])
default
:
default
:
fatalError
(
"Not implemented"
)
fatalError
(
"Not implemented"
)
}
}
...
...
Sources/Extensions/Motion+CALayer.swift
View file @
19e673bf
...
@@ -232,30 +232,30 @@ extension CALayer {
...
@@ -232,30 +232,30 @@ extension CALayer {
case
let
.
transform
(
transform
):
case
let
.
transform
(
transform
):
a
.
append
(
MotionBasicAnimation
.
transform
(
transform
:
transform
))
a
.
append
(
MotionBasicAnimation
.
transform
(
transform
:
transform
))
case
let
.
rotat
ionAngl
e
(
angle
):
case
let
.
rotate
(
angle
):
let
rotate
=
MotionBasicAnimation
.
rotat
ion
(
angle
:
angle
)
let
rotate
=
MotionBasicAnimation
.
rotat
e
(
angle
:
angle
)
a
.
append
(
rotate
)
a
.
append
(
rotate
)
case
let
.
rotat
ionAngl
eX
(
angle
):
case
let
.
rotateX
(
angle
):
a
.
append
(
MotionBasicAnimation
.
rotat
ion
X
(
angle
:
angle
))
a
.
append
(
MotionBasicAnimation
.
rotat
e
X
(
angle
:
angle
))
case
let
.
rotat
ionAngl
eY
(
angle
):
case
let
.
rotateY
(
angle
):
a
.
append
(
MotionBasicAnimation
.
rotat
ion
Y
(
angle
:
angle
))
a
.
append
(
MotionBasicAnimation
.
rotat
e
Y
(
angle
:
angle
))
case
let
.
rotat
ionAngl
eZ
(
angle
):
case
let
.
rotateZ
(
angle
):
a
.
append
(
MotionBasicAnimation
.
rotat
ion
Z
(
angle
:
angle
))
a
.
append
(
MotionBasicAnimation
.
rotat
e
Z
(
angle
:
angle
))
case
let
.
spin
(
rotat
ion
s
):
case
let
.
spin
(
rotat
e
s
):
a
.
append
(
MotionBasicAnimation
.
spin
(
rotat
ions
:
rotation
s
))
a
.
append
(
MotionBasicAnimation
.
spin
(
rotat
es
:
rotate
s
))
case
let
.
spinX
(
rotat
ion
s
):
case
let
.
spinX
(
rotat
e
s
):
a
.
append
(
MotionBasicAnimation
.
spinX
(
rotat
ions
:
rotation
s
))
a
.
append
(
MotionBasicAnimation
.
spinX
(
rotat
es
:
rotate
s
))
case
let
.
spinY
(
rotat
ion
s
):
case
let
.
spinY
(
rotat
e
s
):
a
.
append
(
MotionBasicAnimation
.
spinY
(
rotat
ions
:
rotation
s
))
a
.
append
(
MotionBasicAnimation
.
spinY
(
rotat
es
:
rotate
s
))
case
let
.
spinZ
(
rotat
ion
s
):
case
let
.
spinZ
(
rotat
e
s
):
a
.
append
(
MotionBasicAnimation
.
spinZ
(
rotat
ions
:
rotation
s
))
a
.
append
(
MotionBasicAnimation
.
spinZ
(
rotat
es
:
rotate
s
))
case
let
.
scale
(
to
):
case
let
.
scale
(
to
):
a
.
append
(
MotionBasicAnimation
.
scale
(
to
:
to
))
a
.
append
(
MotionBasicAnimation
.
scale
(
to
:
to
))
...
...
Sources/Extensions/Motion+UIKit.swift
View file @
19e673bf
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
import
UIKit
import
UIKit
fileprivate
let
parameterRegex
=
"(?:
\\
-?
\\
d+(
\\
.?
\\
d+)?)|
\\
w+"
fileprivate
let
parameterRegex
=
"(?:
\\
-?
\\
d+(
\\
.?
\\
d+)?)|
\\
w+"
fileprivate
let
modifier
sRegex
=
"(
\\
w+)(?:
\\
(([^
\\
)]*)
\\
))?"
fileprivate
let
transition
sRegex
=
"(
\\
w+)(?:
\\
(([^
\\
)]*)
\\
))?"
internal
extension
NSObject
{
internal
extension
NSObject
{
func
copyWithArchiver
()
->
Any
?
{
func
copyWithArchiver
()
->
Any
?
{
...
...
Sources/Extensions/Motion+UIView.swift
View file @
19e673bf
...
@@ -170,7 +170,7 @@ public extension UIView {
...
@@ -170,7 +170,7 @@ public extension UIView {
}
}
extension
UIView
{
extension
UIView
{
/// Computes the rotat
ion
of the view.
/// Computes the rotat
e
of the view.
open
var
motionRotationAngle
:
CGFloat
{
open
var
motionRotationAngle
:
CGFloat
{
get
{
get
{
return
CGFloat
(
atan2f
(
Float
(
transform
.
b
),
Float
(
transform
.
a
)))
*
180
/
CGFloat
(
Double
.
pi
)
return
CGFloat
(
atan2f
(
Float
(
transform
.
b
),
Float
(
transform
.
a
)))
*
180
/
CGFloat
(
Double
.
pi
)
...
...
Sources/MotionAnimation.swift
View file @
19e673bf
...
@@ -41,10 +41,10 @@ public enum MotionAnimation {
...
@@ -41,10 +41,10 @@ public enum MotionAnimation {
case
borderWidth
(
CGFloat
)
case
borderWidth
(
CGFloat
)
case
cornerRadius
(
CGFloat
)
case
cornerRadius
(
CGFloat
)
case
transform
(
CATransform3D
)
case
transform
(
CATransform3D
)
case
rotat
ionAngl
e
(
CGFloat
)
case
rotate
(
CGFloat
)
case
rotat
ionAngl
eX
(
CGFloat
)
case
rotateX
(
CGFloat
)
case
rotat
ionAngl
eY
(
CGFloat
)
case
rotateY
(
CGFloat
)
case
rotat
ionAngl
eZ
(
CGFloat
)
case
rotateZ
(
CGFloat
)
case
spin
(
CGFloat
)
case
spin
(
CGFloat
)
case
spinX
(
CGFloat
)
case
spinX
(
CGFloat
)
case
spinY
(
CGFloat
)
case
spinY
(
CGFloat
)
...
@@ -81,10 +81,10 @@ public enum MotionAnimationKeyPath: String {
...
@@ -81,10 +81,10 @@ public enum MotionAnimationKeyPath: String {
case
borderWidth
case
borderWidth
case
cornerRadius
case
cornerRadius
case
transform
case
transform
case
rotat
ion
=
"transform.rotation
"
case
rotat
e
=
"transform.rotate
"
case
rotat
ionX
=
"transform.rotation
.x"
case
rotat
eX
=
"transform.rotate
.x"
case
rotat
ionY
=
"transform.rotation
.y"
case
rotat
eY
=
"transform.rotate
.y"
case
rotat
ionZ
=
"transform.rotation
.z"
case
rotat
eZ
=
"transform.rotate
.z"
case
scale
=
"transform.scale"
case
scale
=
"transform.scale"
case
scaleX
=
"transform.scale.x"
case
scaleX
=
"transform.scale.x"
case
scaleY
=
"transform.scale.y"
case
scaleY
=
"transform.scale.y"
...
@@ -184,90 +184,90 @@ public struct MotionBasicAnimation {
...
@@ -184,90 +184,90 @@ public struct MotionBasicAnimation {
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotat
ion
key path.
Creates a CABasicAnimation for the transform.rotat
e
key path.
- Parameter angle: An optional CGFloat.
- Parameter angle: An optional CGFloat.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotat
ion
(
angle
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
rotat
e
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
ion
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
e
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
angle
/
180
))
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
angle
/
180
))
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotat
ion
.x key path.
Creates a CABasicAnimation for the transform.rotat
e
.x key path.
- Parameter angle: An optional CGFloat.
- Parameter angle: An optional CGFloat.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotat
ion
X
(
angle
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
rotat
e
X
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
ion
X
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
e
X
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
angle
/
180
))
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
angle
/
180
))
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotat
ion
.y key path.
Creates a CABasicAnimation for the transform.rotat
e
.y key path.
- Parameter angle: An optional CGFloat.
- Parameter angle: An optional CGFloat.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotat
ion
Y
(
angle
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
rotat
e
Y
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
ion
Y
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
e
Y
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
angle
/
180
))
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
angle
/
180
))
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotat
ion
.z key path.
Creates a CABasicAnimation for the transform.rotat
e
.z key path.
- Parameter angle: An optional CGFloat.
- Parameter angle: An optional CGFloat.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotat
ion
Z
(
angle
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
rotat
e
Z
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
ion
Z
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
e
Z
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
angle
/
180
))
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
angle
/
180
))
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotat
ion
key path.
Creates a CABasicAnimation for the transform.rotat
e
key path.
- Parameter rotat
ion
s: An optional CGFloat.
- Parameter rotat
e
s: An optional CGFloat.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spin
(
rotat
ion
s
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
spin
(
rotat
e
s
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
ion
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
e
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotat
ion
s
))
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotat
e
s
))
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotat
ion
.x key path.
Creates a CABasicAnimation for the transform.rotat
e
.x key path.
- Parameter rotat
ion
s: An optional CGFloat.
- Parameter rotat
e
s: An optional CGFloat.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spinX
(
rotat
ion
s
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
spinX
(
rotat
e
s
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
ion
X
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
e
X
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotat
ion
s
))
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotat
e
s
))
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotat
ion
.y key path.
Creates a CABasicAnimation for the transform.rotat
e
.y key path.
- Parameter rotat
ion
s: An optional CGFloat.
- Parameter rotat
e
s: An optional CGFloat.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spinY
(
rotat
ion
s
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
spinY
(
rotat
e
s
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
ion
Y
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
e
Y
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotat
ion
s
))
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotat
e
s
))
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotat
ion
.z key path.
Creates a CABasicAnimation for the transform.rotat
e
.z key path.
- Parameter rotat
ion
s: An optional CGFloat.
- Parameter rotat
e
s: An optional CGFloat.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spinZ
(
rotat
ion
s
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
spinZ
(
rotat
e
s
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
ion
Z
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotat
e
Z
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotat
ion
s
))
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotat
e
s
))
return
animation
return
animation
}
}
...
...
Sources/MotionPlugin.swift
View file @
19e673bf
...
@@ -47,18 +47,18 @@ open class MotionPlugin: NSObject, MotionPreprocessor, MotionAnimator {
...
@@ -47,18 +47,18 @@ open class MotionPlugin: NSObject, MotionPreprocessor, MotionAnimator {
/**
/**
Called before any animation.
Called before any animation.
Override this method when you want to preprocess
modifier
s for views
Override this method when you want to preprocess
transition
s for views
- Parameters:
- Parameters:
- context: object holding all parsed and changed
modifier
s,
- context: object holding all parsed and changed
transition
s,
- fromViews: A flattened list of all views from source ViewController
- fromViews: A flattened list of all views from source ViewController
- toViews: A flattened list of all views from destination ViewController
- toViews: A flattened list of all views from destination ViewController
To check a view's
modifier
s:
To check a view's
transition
s:
context[view]
context[view]
context[view, "modifierName"]
context[view, "modifierName"]
To set a view's
modifier
s:
To set a view's
transition
s:
context[view] = [("modifier1", ["parameter1"]), ("modifier2", [])]
context[view] = [("modifier1", ["parameter1"]), ("modifier2", [])]
context[view, "modifier1"] = ["parameter1", "parameter2"]
context[view, "modifier1"] = ["parameter1", "parameter2"]
...
@@ -69,7 +69,7 @@ open class MotionPlugin: NSObject, MotionPreprocessor, MotionAnimator {
...
@@ -69,7 +69,7 @@ open class MotionPlugin: NSObject, MotionPreprocessor, MotionAnimator {
/**
/**
- Returns: return true if the plugin can handle animating the view.
- Returns: return true if the plugin can handle animating the view.
- Parameters:
- Parameters:
- context: object holding all parsed and changed
modifier
s,
- context: object holding all parsed and changed
transition
s,
- view: the view to check whether or not the plugin can handle the animation
- view: the view to check whether or not the plugin can handle the animation
- isAppearing: true if the view is isAppearing(i.e. a view in destination ViewController)
- isAppearing: true if the view is isAppearing(i.e. a view in destination ViewController)
If return true, Motion won't animate and won't let any other plugins animate this view.
If return true, Motion won't animate and won't let any other plugins animate this view.
...
@@ -82,7 +82,7 @@ open class MotionPlugin: NSObject, MotionPreprocessor, MotionAnimator {
...
@@ -82,7 +82,7 @@ open class MotionPlugin: NSObject, MotionPreprocessor, MotionAnimator {
Note: views in `fromViews` & `toViews` are hidden already. Unhide then if you need to take snapshots.
Note: views in `fromViews` & `toViews` are hidden already. Unhide then if you need to take snapshots.
- Parameters:
- Parameters:
- context: object holding all parsed and changed
modifier
s,
- context: object holding all parsed and changed
transition
s,
- fromViews: A flattened list of all views from source ViewController (filtered by `canAnimate`)
- fromViews: A flattened list of all views from source ViewController (filtered by `canAnimate`)
- toViews: A flattened list of all views from destination ViewController (filtered by `canAnimate`)
- toViews: A flattened list of all views from destination ViewController (filtered by `canAnimate`)
- Returns: The duration needed to complete the animation
- Returns: The duration needed to complete the animation
...
@@ -121,7 +121,7 @@ open class MotionPlugin: NSObject, MotionPreprocessor, MotionAnimator {
...
@@ -121,7 +121,7 @@ open class MotionPlugin: NSObject, MotionPreprocessor, MotionAnimator {
/**
/**
For supporting interactive animation only.
For supporting interactive animation only.
This method is called when user wants to override animation
modifier
s during an interactive animation
This method is called when user wants to override animation
transition
s during an interactive animation
- Parameters:
- Parameters:
- state: the target state to override
- state: the target state to override
...
...
Sources/MotionTargetState.swift
View file @
19e673bf
...
@@ -93,7 +93,7 @@ public struct MotionTargetState {
...
@@ -93,7 +93,7 @@ public struct MotionTargetState {
public
var
timingFunction
:
CAMediaTimingFunction
?
public
var
timingFunction
:
CAMediaTimingFunction
?
public
var
arc
:
CGFloat
?
public
var
arc
:
CGFloat
?
public
var
source
:
String
?
public
var
motionIdentifier
:
String
?
public
var
cascade
:
(
TimeInterval
,
CascadeDirection
,
Bool
)?
public
var
cascade
:
(
TimeInterval
,
CascadeDirection
,
Bool
)?
public
var
ignoreSubviewModifiers
:
Bool
?
public
var
ignoreSubviewModifiers
:
Bool
?
...
...
Sources/MotionTransition+MotionStringConvertible.swift
View file @
19e673bf
...
@@ -38,14 +38,14 @@ extension MotionTransition: MotionStringConvertible {
...
@@ -38,14 +38,14 @@ extension MotionTransition: MotionStringConvertible {
case
"fade"
:
case
"fade"
:
return
.
fade
return
.
fade
case
"opacity"
:
case
"opacity"
:
return
MotionTransition
.
opacity
(
parameters
.
getFloat
(
0
)
??
1
)
return
MotionTransition
.
fade
(
to
:
parameters
.
getFloat
(
0
)
??
1
)
case
"position"
:
case
"position"
:
return
.
position
(
CGPoint
(
x
:
parameters
.
getCGFloat
(
0
)
??
0
,
y
:
parameters
.
getCGFloat
(
1
)
??
0
))
return
.
position
(
to
:
CGPoint
(
x
:
parameters
.
getCGFloat
(
0
)
??
0
,
y
:
parameters
.
getCGFloat
(
1
)
??
0
))
case
"size"
:
case
"size"
:
return
.
size
(
CGSize
(
width
:
parameters
.
getCGFloat
(
0
)
??
0
,
height
:
parameters
.
getCGFloat
(
1
)
??
0
))
return
.
size
(
CGSize
(
width
:
parameters
.
getCGFloat
(
0
)
??
0
,
height
:
parameters
.
getCGFloat
(
1
)
??
0
))
case
"scale"
:
case
"scale"
:
if
parameters
.
count
==
1
{
if
parameters
.
count
==
1
{
return
.
scale
(
parameters
.
getCGFloat
(
0
)
??
1
)
return
.
scale
(
to
:
parameters
.
getCGFloat
(
0
)
??
1
)
}
else
{
}
else
{
return
.
scale
(
x
:
parameters
.
getCGFloat
(
0
)
??
1
,
return
.
scale
(
x
:
parameters
.
getCGFloat
(
0
)
??
1
,
y
:
parameters
.
getCGFloat
(
1
)
??
1
,
y
:
parameters
.
getCGFloat
(
1
)
??
1
,
...
@@ -73,8 +73,8 @@ extension MotionTransition: MotionStringConvertible {
...
@@ -73,8 +73,8 @@ extension MotionTransition: MotionStringConvertible {
if
let
duration
=
parameters
.
getDouble
(
0
)
{
if
let
duration
=
parameters
.
getDouble
(
0
)
{
return
.
duration
(
duration
)
return
.
duration
(
duration
)
}
}
case
"
durationMatch
Longest"
:
case
"
preferredDurationMatches
Longest"
:
return
.
durationMatch
Longest
return
.
preferredDurationMatches
Longest
case
"delay"
:
case
"delay"
:
if
let
delay
=
parameters
.
getDouble
(
0
)
{
if
let
delay
=
parameters
.
getDouble
(
0
)
{
return
.
delay
(
delay
)
return
.
delay
(
delay
)
...
@@ -100,10 +100,10 @@ extension MotionTransition: MotionStringConvertible {
...
@@ -100,10 +100,10 @@ extension MotionTransition: MotionStringConvertible {
let
direction
=
CascadeDirection
(
directionString
)
{
let
direction
=
CascadeDirection
(
directionString
)
{
cascadeDirection
=
direction
cascadeDirection
=
direction
}
}
return
.
cascade
(
delta
:
parameters
.
getDouble
(
0
)
??
0.02
,
direction
:
cascadeDirection
,
delay
MatchedViews
:
parameters
.
getBool
(
2
)
??
false
)
return
.
cascade
(
delta
:
parameters
.
getDouble
(
0
)
??
0.02
,
direction
:
cascadeDirection
,
animationDelayUntil
MatchedViews
:
parameters
.
getBool
(
2
)
??
false
)
case
"source"
:
case
"source"
:
if
let
motionIdentifier
=
parameters
.
get
(
0
)?
.
name
{
if
let
motionIdentifier
=
parameters
.
get
(
0
)?
.
name
{
return
.
source
(
motionIdentifier
:
motionIdentifier
)
return
.
motionIdentifier
(
motionIdentifier
)
}
}
case
"useGlobalCoordinateSpace"
:
case
"useGlobalCoordinateSpace"
:
return
.
useGlobalCoordinateSpace
return
.
useGlobalCoordinateSpace
...
...
Sources/MotionTransition.swift
View file @
19e673bf
This diff is collapsed.
Click to expand it.
Sources/Preprocessors/BasePreprocessor.swift
deleted
100644 → 0
View file @
06ec8deb
/*
* The MIT License (MIT)
*
* Copyright (C) 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Original Inspiration & Author
* Copyright (c) 2016 Luke Zhao <me@lkzhao.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import
UIKit
class
BasePreprocessor
:
MotionPreprocessor
{
weak
public
var
context
:
MotionContext
!
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{}
}
Sources/Preprocessors/CascadePreprocessor.swift
View file @
19e673bf
...
@@ -70,8 +70,11 @@ public enum CascadeDirection {
...
@@ -70,8 +70,11 @@ public enum CascadeDirection {
}
}
}
}
class
CascadePreprocessor
:
BasePreprocessor
{
class
CascadePreprocessor
:
MotionPreprocessor
{
override
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
/// A reference to a MotionContext.
weak
var
context
:
MotionContext
!
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
process
(
views
:
fromViews
)
process
(
views
:
fromViews
)
process
(
views
:
toViews
)
process
(
views
:
toViews
)
}
}
...
...
Sources/Preprocessors/DurationPreprocessor.swift
View file @
19e673bf
...
@@ -8,15 +8,22 @@
...
@@ -8,15 +8,22 @@
import
UIKit
import
UIKit
class
DurationPreprocessor
:
BasePreprocessor
{
class
DurationPreprocessor
:
MotionPreprocessor
{
/// A reference to a MotionContext.
override
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
weak
var
context
:
MotionContext
!
var
maxDuration
:
TimeInterval
=
0
maxDuration
=
applyOptimizedDurationIfNoDuration
(
views
:
fromViews
)
/**
maxDuration
=
max
(
maxDuration
,
applyOptimizedDurationIfNoDuration
(
views
:
toViews
))
Implementation for processor.
setDurationForInfiniteDuration
(
views
:
fromViews
,
duration
:
maxDuration
)
- Parameter fromViews: An Array of UIViews.
setDurationForInfiniteDuration
(
views
:
toViews
,
duration
:
maxDuration
)
- Parameter toViews: An Array of UIViews.
}
*/
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
var
maxDuration
:
TimeInterval
=
0
maxDuration
=
applyOptimizedDurationIfNoDuration
(
views
:
fromViews
)
maxDuration
=
max
(
maxDuration
,
applyOptimizedDurationIfNoDuration
(
views
:
toViews
))
setDurationForInfiniteDuration
(
views
:
fromViews
,
duration
:
maxDuration
)
setDurationForInfiniteDuration
(
views
:
toViews
,
duration
:
maxDuration
)
}
func
optimizedDurationFor
(
view
:
UIView
)
->
TimeInterval
{
func
optimizedDurationFor
(
view
:
UIView
)
->
TimeInterval
{
let
targetState
=
context
[
view
]
!
let
targetState
=
context
[
view
]
!
...
...
Sources/Preprocessors/IgnoreSubviewModifiersPreprocessor.swift
View file @
19e673bf
...
@@ -28,8 +28,11 @@
...
@@ -28,8 +28,11 @@
import
UIKit
import
UIKit
class
IgnoreSubviewModifiersPreprocessor
:
BasePreprocessor
{
class
IgnoreSubviewModifiersPreprocessor
:
MotionPreprocessor
{
override
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
/// A reference to a MotionContext.
weak
var
context
:
MotionContext
!
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
process
(
views
:
fromViews
)
process
(
views
:
fromViews
)
process
(
views
:
toViews
)
process
(
views
:
toViews
)
}
}
...
...
Sources/Preprocessors/MatchPreprocessor.swift
View file @
19e673bf
...
@@ -28,49 +28,57 @@
...
@@ -28,49 +28,57 @@
import
UIKit
import
UIKit
class
MatchPreprocessor
:
BasePreprocessor
{
class
MatchPreprocessor
:
MotionPreprocessor
{
override
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
/// A reference to a MotionContext.
for
tv
in
toViews
{
weak
var
context
:
MotionContext
!
guard
let
id
=
tv
.
motionIdentifier
,
let
fv
=
context
.
sourceView
(
for
:
id
)
else
{
continue
}
/**
var
tvState
=
context
[
tv
]
??
MotionTargetState
()
Implementation for processor.
var
fvState
=
context
[
fv
]
??
MotionTargetState
()
- Parameter fromViews: An Array of UIViews.
- Parameter toViews: An Array of UIViews.
if
let
beginStateIfMatched
=
tvState
.
beginStateIfMatched
{
*/
tvState
.
append
(
.
beginWith
(
modifiers
:
beginStateIfMatched
))
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
}
for
tv
in
toViews
{
if
let
beginStateIfMatched
=
fvState
.
beginStateIfMatched
{
guard
let
id
=
tv
.
motionIdentifier
,
let
fv
=
context
.
sourceView
(
for
:
id
)
else
{
continue
}
fvState
.
append
(
.
beginWith
(
modifiers
:
beginStateIfMatched
))
}
var
tvState
=
context
[
tv
]
??
MotionTargetState
()
var
fvState
=
context
[
fv
]
??
MotionTargetState
()
// match is just a two-way source effect
tvState
.
source
=
id
if
let
beginStateIfMatched
=
tvState
.
beginStateIfMatched
{
fvState
.
source
=
id
tvState
.
append
(
.
beginWith
(
transitions
:
beginStateIfMatched
))
}
fvState
.
arc
=
tvState
.
arc
if
let
beginStateIfMatched
=
fvState
.
beginStateIfMatched
{
fvState
.
duration
=
tvState
.
duration
fvState
.
append
(
.
beginWith
(
transitions
:
beginStateIfMatched
))
fvState
.
timingFunction
=
tvState
.
timingFunction
}
fvState
.
delay
=
tvState
.
delay
fvState
.
spring
=
tvState
.
spring
// match is just a two-way source effect
tvState
.
motionIdentifier
=
id
tvState
.
opacity
=
0
fvState
.
motionIdentifier
=
id
let
forceNonFade
=
tvState
.
nonFade
||
fvState
.
nonFade
let
isNonOpaque
=
!
fv
.
isOpaque
||
fv
.
alpha
<
1
||
!
tv
.
isOpaque
||
tv
.
alpha
<
1
fvState
.
arc
=
tvState
.
arc
if
!
forceNonFade
&&
isNonOpaque
{
fvState
.
duration
=
tvState
.
duration
// cross fade if from/toViews are not opaque
fvState
.
timingFunction
=
tvState
.
timingFunction
fvState
.
opacity
=
0
fvState
.
delay
=
tvState
.
delay
}
else
{
fvState
.
spring
=
tvState
.
spring
// no cross fade in this case, fromView is always displayed during the transition.
fvState
.
opacity
=
nil
tvState
.
opacity
=
0
let
forceNonFade
=
tvState
.
nonFade
||
fvState
.
nonFade
// we dont want two shadows showing up. Therefore we disable toView's shadow when fromView is able to display its shadow
let
isNonOpaque
=
!
fv
.
isOpaque
||
fv
.
alpha
<
1
||
!
tv
.
isOpaque
||
tv
.
alpha
<
1
if
!
fv
.
layer
.
masksToBounds
&&
fvState
.
displayShadow
{
if
!
forceNonFade
&&
isNonOpaque
{
tvState
.
displayShadow
=
false
// cross fade if from/toViews are not opaque
fvState
.
opacity
=
0
}
else
{
// no cross fade in this case, fromView is always displayed during the transition.
fvState
.
opacity
=
nil
// we dont want two shadows showing up. Therefore we disable toView's shadow when fromView is able to display its shadow
if
!
fv
.
layer
.
masksToBounds
&&
fvState
.
displayShadow
{
tvState
.
displayShadow
=
false
}
}
context
[
tv
]
=
tvState
context
[
fv
]
=
fvState
}
}
}
context
[
tv
]
=
tvState
context
[
fv
]
=
fvState
}
}
}
}
}
Sources/Preprocessors/SourcePreprocessor.swift
View file @
19e673bf
...
@@ -28,15 +28,18 @@
...
@@ -28,15 +28,18 @@
import
UIKit
import
UIKit
class
SourcePreprocessor
:
BasePreprocessor
{
class
SourcePreprocessor
:
MotionPreprocessor
{
override
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
/// A reference to a MotionContext.
weak
var
context
:
MotionContext
!
func
process
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
{
for
fv
in
fromViews
{
for
fv
in
fromViews
{
guard
let
id
=
context
[
fv
]?
.
source
,
guard
let
id
=
context
[
fv
]?
.
motionIdentifier
,
let
tv
=
context
.
destinationView
(
for
:
id
)
else
{
continue
}
let
tv
=
context
.
destinationView
(
for
:
id
)
else
{
continue
}
prepareFor
(
view
:
fv
,
targetView
:
tv
)
prepareFor
(
view
:
fv
,
targetView
:
tv
)
}
}
for
tv
in
toViews
{
for
tv
in
toViews
{
guard
let
id
=
context
[
tv
]?
.
source
,
guard
let
id
=
context
[
tv
]?
.
motionIdentifier
,
let
fv
=
context
.
sourceView
(
for
:
id
)
else
{
continue
}
let
fv
=
context
.
sourceView
(
for
:
id
)
else
{
continue
}
prepareFor
(
view
:
tv
,
targetView
:
fv
)
prepareFor
(
view
:
tv
,
targetView
:
fv
)
}
}
...
...
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