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
5e35f736
Unverified
Commit
5e35f736
authored
Jan 27, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: added animation rotation to MotionTransition
parent
1cfbad4a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
56 deletions
+59
-56
Sources/iOS/MotionAnimation.swift
+48
-50
Sources/iOS/MotionTransition.swift
+11
-6
No files found.
Sources/iOS/MotionAnimation.swift
View file @
5e35f736
...
...
@@ -63,18 +63,18 @@ public enum MotionAnimation {
case
backgroundColor
(
UIColor
)
case
corners
(
CGFloat
)
case
transform
(
CATransform3D
)
case
rotate
(
CGFloat
)
case
rotateX
(
CGFloat
)
case
rotateY
(
CGFloat
)
case
rotateZ
(
CGFloat
)
case
spin
(
CGFloat
)
case
spinX
(
CGFloat
)
case
spinY
(
CGFloat
)
case
spinZ
(
CGFloat
)
case
scale
(
CGFloat
)
case
scaleX
(
CGFloat
)
case
scaleY
(
CGFloat
)
case
scaleZ
(
CGFloat
)
case
rotate
(
Double
)
case
rotateX
(
Double
)
case
rotateY
(
Double
)
case
rotateZ
(
Double
)
case
spin
(
Double
)
case
spinX
(
Double
)
case
spinY
(
Double
)
case
spinZ
(
Double
)
case
scale
(
Double
)
case
scaleX
(
Double
)
case
scaleY
(
Double
)
case
scaleZ
(
Double
)
case
translate
(
x
:
CGFloat
,
y
:
CGFloat
)
case
translateX
(
CGFloat
)
case
translateY
(
CGFloat
)
...
...
@@ -84,7 +84,7 @@ public enum MotionAnimation {
case
point
(
x
:
CGFloat
,
y
:
CGFloat
)
case
position
(
x
:
CGFloat
,
y
:
CGFloat
)
case
shadow
(
path
:
CGPath
)
case
fade
(
CGFloat
)
case
fade
(
Double
)
case
zPosition
(
Int
)
case
width
(
CGFloat
)
case
height
(
CGFloat
)
...
...
@@ -234,8 +234,6 @@ extension CALayer {
a
.
append
(
Motion
.
transform
(
transform
:
transform
))
case
let
.
rotate
(
angle
):
let
rotate
=
Motion
.
rotate
(
angle
:
angle
)
let
radians
=
CGFloat
(
atan2f
(
Float
(
s
.
affineTransform
()
.
b
),
Float
(
s
.
affineTransform
()
.
a
)))
rotate
.
fromValue
=
radians
*
180
/
CGFloat
(
M_PI
)
a
.
append
(
rotate
)
case
let
.
rotateX
(
angle
):
a
.
append
(
Motion
.
rotateX
(
angle
:
angle
))
...
...
@@ -370,98 +368,98 @@ extension Motion {
/**
Creates a CABasicAnimation for the transform.rotation key path.
- Parameter angle: An optional
CGFloat
.
- Parameter angle: An optional
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
rotate
(
angle
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
rotate
(
angle
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
angle
/
180
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter angle: An optional
CGFloat
.
- Parameter angle: An optional
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
rotateX
(
angle
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
rotateX
(
angle
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
angle
/
180
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter angle: An optional
CGFloat
.
- Parameter angle: An optional
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
rotateY
(
angle
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
rotateY
(
angle
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
angle
/
180
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter angle: An optional
CGFloat
.
- Parameter angle: An optional
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
rotateZ
(
angle
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
rotateZ
(
angle
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
angle
/
180
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.rotation key path.
- Parameter rotations: An optional
CGFloat
.
- Parameter rotations: An optional
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
spin
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
spin
(
rotations
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
2
*
rotations
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter rotations: An optional
CGFloat
.
- Parameter rotations: An optional
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
spinX
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
spinX
(
rotations
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
2
*
rotations
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter rotations: An optional
CGFloat
.
- Parameter rotations: An optional
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
spinY
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
spinY
(
rotations
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
2
*
rotations
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter rotations: An optional
CGFloat
.
- Parameter rotations: An optional
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
spinZ
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
spinZ
(
rotations
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
2
*
rotations
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.scale key path.
- Parameter to scale: A
CGFloat
.
- Parameter to scale: A
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
scale
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
scale
(
to
scale
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scale
)
animation
.
toValue
=
scale
as
NSNumber
return
animation
...
...
@@ -469,10 +467,10 @@ extension Motion {
/**
Creates a CABasicAnimation for the transform.scale.x key path.
- Parameter to scale: A
CGFloat
.
- Parameter to scale: A
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
scaleX
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
scaleX
(
to
scale
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleX
)
animation
.
toValue
=
scale
as
NSNumber
return
animation
...
...
@@ -480,10 +478,10 @@ extension Motion {
/**
Creates a CABasicAnimation for the transform.scale.y key path.
- Parameter to scale: A
CGFloat
.
- Parameter to scale: A
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
scaleY
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
scaleY
(
to
scale
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleY
)
animation
.
toValue
=
scale
as
NSNumber
return
animation
...
...
@@ -491,10 +489,10 @@ extension Motion {
/**
Creates a CABasicAnimation for the transform.scale.z key path.
- Parameter to scale: A
CGFloat
.
- Parameter to scale: A
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
scaleZ
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
scaleZ
(
to
scale
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleZ
)
animation
.
toValue
=
scale
as
NSNumber
return
animation
...
...
@@ -580,12 +578,12 @@ extension Motion {
/**
Creates a CABasicAnimation for the opacity key path.
- Parameter opacity: A
CGFloat
.
- Parameter opacity: A
Double
.
- Returns: A CABasicAnimation.
*/
public
static
func
fade
(
opacity
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
fade
(
opacity
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
opacity
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
opacity
)
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
opacity
)
return
animation
}
...
...
Sources/iOS/MotionTransition.swift
View file @
5e35f736
...
...
@@ -42,6 +42,11 @@ fileprivate struct MotionTransitionItemController {
fileprivate
var
delegate
:
MotionTransitionDelegate
}
fileprivate
func
getRotationInDegrees
(
view
:
UIView
)
->
Double
{
let
radians
=
Double
(
atan2f
(
Float
(
view
.
transform
.
b
),
Float
(
view
.
transform
.
a
)))
return
ceil
(
radians
*
180
/
M_PI
)
}
extension
UIViewController
{
/// MaterialLayer Reference.
fileprivate
var
motionTransition
:
MotionTransitionItemController
{
...
...
@@ -128,7 +133,7 @@ extension UIView {
let
oldCornerRadius
=
view
.
cornerRadius
view
.
cornerRadius
=
0
let
oldRotation
=
view
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
as?
CGFloat
??
0
let
oldRotation
=
view
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
??
0
view
.
layer
.
setValue
(
0
,
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
let
v
=
view
.
snapshotView
(
afterScreenUpdates
:
afterUpdates
)
!
...
...
@@ -158,7 +163,7 @@ extension UIView {
v
.
shadowColor
=
view
.
shadowColor
v
.
shadowOffset
=
view
.
shadowOffset
v
.
contentMode
=
view
.
contentMode
v
.
layer
.
transform
=
view
.
layer
.
transform
//
v.layer.transform = view.layer.transform
view
.
isHidden
=
true
(
view
as?
Pulseable
)?
.
pulse
.
pulseLayer
?
.
isHidden
=
false
...
...
@@ -376,8 +381,8 @@ open class MotionTransitionPresentedAnimator: MotionTransitionAnimator {
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
)
as?
CGFloat
??
0
let
rotateAnimation
=
Motion
.
rotate
(
angle
:
getRotationInDegrees
(
view
:
toView
)
)
//rotateAnimation.fromValue = getRotationInDegrees(view: fromView)
snapshotAnimations
.
append
(
rotateAnimation
)
let
cornerRadiusAnimation
=
Motion
.
corner
(
radius
:
toView
.
cornerRadius
)
...
...
@@ -492,8 +497,8 @@ open class MotionTransitionDismissedAnimator: MotionTransitionAnimator {
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
)
as?
CGFloat
??
0
let
rotateAnimation
=
Motion
.
rotate
(
angle
:
getRotationInDegrees
(
view
:
toView
)
)
//rotateAnimation.fromValue = getRotationInDegrees(view: fromView)
snapshotAnimations
.
append
(
rotateAnimation
)
let
cornerRadiusAnimation
=
Motion
.
corner
(
radius
:
toView
.
cornerRadius
)
...
...
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