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
3d538a63
Unverified
Commit
3d538a63
authored
Feb 01, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: updated transform behaviour when setting up MotionTransition
parent
c7200fdf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
84 deletions
+91
-84
Sources/iOS/MotionAnimation.swift
+65
-60
Sources/iOS/MotionTransition.swift
+26
-24
No files found.
Sources/iOS/MotionAnimation.swift
View file @
3d538a63
...
@@ -61,20 +61,20 @@ public enum MotionAnimation {
...
@@ -61,20 +61,20 @@ public enum MotionAnimation {
case
duration
(
TimeInterval
)
case
duration
(
TimeInterval
)
case
custom
(
CABasicAnimation
)
case
custom
(
CABasicAnimation
)
case
backgroundColor
(
UIColor
)
case
backgroundColor
(
UIColor
)
case
corners
(
CGFloat
)
case
corner
Radiu
s
(
CGFloat
)
case
transform
(
CATransform3D
)
case
transform
(
CATransform3D
)
case
rotat
e
(
Double
)
case
rotat
ionAngle
(
CGFloat
)
case
rotat
eX
(
Double
)
case
rotat
ionAngleX
(
CGFloat
)
case
rotat
eY
(
Double
)
case
rotat
ionAngleY
(
CGFloat
)
case
rotat
eZ
(
Double
)
case
rotat
ionAngleZ
(
CGFloat
)
case
spin
(
Double
)
case
spin
(
CGFloat
)
case
spinX
(
Double
)
case
spinX
(
CGFloat
)
case
spinY
(
Double
)
case
spinY
(
CGFloat
)
case
spinZ
(
Double
)
case
spinZ
(
CGFloat
)
case
scale
(
Double
)
case
scale
(
CGFloat
)
case
scaleX
(
Double
)
case
scaleX
(
CGFloat
)
case
scaleY
(
Double
)
case
scaleY
(
CGFloat
)
case
scaleZ
(
Double
)
case
scaleZ
(
CGFloat
)
case
translate
(
x
:
CGFloat
,
y
:
CGFloat
)
case
translate
(
x
:
CGFloat
,
y
:
CGFloat
)
case
translateX
(
CGFloat
)
case
translateX
(
CGFloat
)
case
translateY
(
CGFloat
)
case
translateY
(
CGFloat
)
...
@@ -243,19 +243,19 @@ extension CALayer {
...
@@ -243,19 +243,19 @@ extension CALayer {
a
.
append
(
animation
)
a
.
append
(
animation
)
case
let
.
backgroundColor
(
color
):
case
let
.
backgroundColor
(
color
):
a
.
append
(
Motion
.
background
(
color
:
color
))
a
.
append
(
Motion
.
background
(
color
:
color
))
case
let
.
corners
(
radius
):
case
let
.
corner
Radiu
s
(
radius
):
a
.
append
(
Motion
.
corner
(
radius
:
radius
))
a
.
append
(
Motion
.
corner
(
radius
:
radius
))
case
let
.
transform
(
transform
):
case
let
.
transform
(
transform
):
a
.
append
(
Motion
.
transform
(
transform
:
transform
))
a
.
append
(
Motion
.
transform
(
transform
:
transform
))
case
let
.
rotate
(
angle
):
case
let
.
rotat
ionAngl
e
(
angle
):
let
rotate
=
Motion
.
rotat
e
(
angle
:
angle
)
let
rotate
=
Motion
.
rotat
ion
(
angle
:
angle
)
a
.
append
(
rotate
)
a
.
append
(
rotate
)
case
let
.
rotateX
(
angle
):
case
let
.
rotat
ionAngl
eX
(
angle
):
a
.
append
(
Motion
.
rotat
e
X
(
angle
:
angle
))
a
.
append
(
Motion
.
rotat
ion
X
(
angle
:
angle
))
case
let
.
rotateY
(
angle
):
case
let
.
rotat
ionAngl
eY
(
angle
):
a
.
append
(
Motion
.
rotat
e
Y
(
angle
:
angle
))
a
.
append
(
Motion
.
rotat
ion
Y
(
angle
:
angle
))
case
let
.
rotateZ
(
angle
):
case
let
.
rotat
ionAngl
eZ
(
angle
):
a
.
append
(
Motion
.
rotat
e
Z
(
angle
:
angle
))
a
.
append
(
Motion
.
rotat
ion
Z
(
angle
:
angle
))
case
let
.
spin
(
rotations
):
case
let
.
spin
(
rotations
):
a
.
append
(
Motion
.
spin
(
rotations
:
rotations
))
a
.
append
(
Motion
.
spin
(
rotations
:
rotations
))
case
let
.
spinX
(
rotations
):
case
let
.
spinX
(
rotations
):
...
@@ -316,8 +316,13 @@ extension CALayer: CAAnimationDelegate {}
...
@@ -316,8 +316,13 @@ extension CALayer: CAAnimationDelegate {}
extension
UIView
{
extension
UIView
{
/// Computes the rotation of the view.
/// Computes the rotation of the view.
open
var
motionRotationAngle
:
Double
{
open
var
motionRotationAngle
:
CGFloat
{
return
Double
(
atan2f
(
Float
(
transform
.
b
),
Float
(
transform
.
a
)))
*
180
/
M_PI
get
{
return
CGFloat
(
atan2f
(
Float
(
transform
.
b
),
Float
(
transform
.
a
)))
*
180
/
CGFloat
(
M_PI
)
}
set
(
value
)
{
transform
=
CGAffineTransform
(
rotationAngle
:
CGFloat
(
M_PI
)
*
value
/
180
)
}
}
}
/// Computes the scale X axis value of the view.
/// Computes the scale X axis value of the view.
...
@@ -413,133 +418,133 @@ extension Motion {
...
@@ -413,133 +418,133 @@ extension Motion {
/**
/**
Creates a CABasicAnimation for the transform.rotation key path.
Creates a CABasicAnimation for the transform.rotation key path.
- Parameter angle: An optional
Double
.
- Parameter angle: An optional
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotat
e
(
angle
:
Double
)
->
CABasicAnimation
{
public
static
func
rotat
ion
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
angle
/
180
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
CGFloat
(
M_PI
)
*
angle
/
180
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.x key path.
Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter angle: An optional
Double
.
- Parameter angle: An optional
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotat
eX
(
angle
:
Double
)
->
CABasicAnimation
{
public
static
func
rotat
ionX
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
angle
/
180
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
CGFloat
(
M_PI
)
*
angle
/
180
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.y key path.
Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter angle: An optional
Double
.
- Parameter angle: An optional
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotat
eY
(
angle
:
Double
)
->
CABasicAnimation
{
public
static
func
rotat
ionY
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
angle
/
180
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
CGFloat
(
M_PI
)
*
angle
/
180
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.z key path.
Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter angle: An optional
Double
.
- Parameter angle: An optional
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotat
eZ
(
angle
:
Double
)
->
CABasicAnimation
{
public
static
func
rotat
ionZ
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
angle
/
180
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
CGFloat
(
M_PI
)
*
angle
/
180
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation key path.
Creates a CABasicAnimation for the transform.rotation key path.
- Parameter rotations: An optional
Double
.
- Parameter rotations: An optional
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spin
(
rotations
:
Double
)
->
CABasicAnimation
{
public
static
func
spin
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
2
*
rotations
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
CGFloat
(
M_PI
)
*
2
*
rotations
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.x key path.
Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter rotations: An optional
Double
.
- Parameter rotations: An optional
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spinX
(
rotations
:
Double
)
->
CABasicAnimation
{
public
static
func
spinX
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
2
*
rotations
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
CGFloat
(
M_PI
)
*
2
*
rotations
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.y key path.
Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter rotations: An optional
Double
.
- Parameter rotations: An optional
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spinY
(
rotations
:
Double
)
->
CABasicAnimation
{
public
static
func
spinY
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
2
*
rotations
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
CGFloat
(
M_PI
)
*
2
*
rotations
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.z key path.
Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter rotations: An optional
Double
.
- Parameter rotations: An optional
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spinZ
(
rotations
:
Double
)
->
CABasicAnimation
{
public
static
func
spinZ
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
M_PI
*
2
*
rotations
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
CGFloat
(
M_PI
)
*
2
*
rotations
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.scale key path.
Creates a CABasicAnimation for the transform.scale key path.
- Parameter to scale: A
Double
.
- Parameter to scale: A
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
scale
(
to
scale
:
Double
)
->
CABasicAnimation
{
public
static
func
scale
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scale
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
scale
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.scale.x key path.
Creates a CABasicAnimation for the transform.scale.x key path.
- Parameter to scale: A
Double
.
- Parameter to scale: A
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
scaleX
(
to
scale
:
Double
)
->
CABasicAnimation
{
public
static
func
scaleX
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleX
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleX
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
scale
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.scale.y key path.
Creates a CABasicAnimation for the transform.scale.y key path.
- Parameter to scale: A
Double
.
- Parameter to scale: A
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
scaleY
(
to
scale
:
Double
)
->
CABasicAnimation
{
public
static
func
scaleY
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleY
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleY
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
scale
)
)
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.scale.z key path.
Creates a CABasicAnimation for the transform.scale.z key path.
- Parameter to scale: A
Double
.
- Parameter to scale: A
CGFloat
.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
scaleZ
(
to
scale
:
Double
)
->
CABasicAnimation
{
public
static
func
scaleZ
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleZ
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleZ
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
scale
)
)
return
animation
return
animation
}
}
...
...
Sources/iOS/MotionTransition.swift
View file @
3d538a63
...
@@ -84,17 +84,17 @@ extension UIViewController {
...
@@ -84,17 +84,17 @@ extension UIViewController {
}
}
}
}
//
extension UIViewController {
extension
UIViewController
{
//
open func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
open
func
navigationController
(
_
navigationController
:
UINavigationController
,
animationControllerFor
operation
:
UINavigationControllerOperation
,
from
fromVC
:
UIViewController
,
to
toVC
:
UIViewController
)
->
UIViewControllerAnimatedTransitioning
?
{
//
return isMotionTransitionEnabled ? MotionTransition(isPresenting: operation == .push) : nil
return
isMotionTransitionEnabled
?
MotionTransition
(
isPresenting
:
operation
==
.
push
)
:
nil
//
}
}
//
}
}
//
//
extension UIViewController {
extension
UIViewController
{
//
open func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
open
func
tabBarController
(
_
tabBarController
:
UITabBarController
,
animationControllerForTransitionFrom
fromVC
:
UIViewController
,
to
toVC
:
UIViewController
)
->
UIViewControllerAnimatedTransitioning
?
{
//
return isMotionTransitionEnabled ? MotionTransition() : nil
return
isMotionTransitionEnabled
?
MotionTransition
()
:
nil
//
}
}
//
}
}
extension
UIView
{
extension
UIView
{
/// The global position of a view.
/// The global position of a view.
...
@@ -143,11 +143,13 @@ extension UIView {
...
@@ -143,11 +143,13 @@ extension UIView {
let
oldBackgroundColor
=
backgroundColor
let
oldBackgroundColor
=
backgroundColor
backgroundColor
=
.
clear
backgroundColor
=
.
clear
let
oldTransform
=
transform
transform
=
.
identity
let
v
=
snapshotView
(
afterScreenUpdates
:
afterUpdates
)
!
let
v
=
snapshotView
(
afterScreenUpdates
:
afterUpdates
)
!
cornerRadius
=
oldCornerRadius
cornerRadius
=
oldCornerRadius
backgroundColor
=
oldBackgroundColor
backgroundColor
=
oldBackgroundColor
v
.
backgroundColor
=
oldBackgroundColor
transform
=
oldTransform
let
contentView
=
v
.
subviews
.
first
!
let
contentView
=
v
.
subviews
.
first
!
contentView
.
cornerRadius
=
cornerRadius
contentView
.
cornerRadius
=
cornerRadius
...
@@ -169,7 +171,10 @@ extension UIView {
...
@@ -169,7 +171,10 @@ extension UIView {
v
.
shadowColor
=
shadowColor
v
.
shadowColor
=
shadowColor
v
.
shadowOffset
=
shadowOffset
v
.
shadowOffset
=
shadowOffset
v
.
contentMode
=
contentMode
v
.
contentMode
=
contentMode
v
.
layer
.
transform
=
layer
.
transform
v
.
transform
=
transform
v
.
backgroundColor
=
backgroundColor
print
(
motionRotationAngle
)
isHidden
=
true
isHidden
=
true
(
self
as?
Pulseable
)?
.
pulse
.
pulseLayer
?
.
isHidden
=
false
(
self
as?
Pulseable
)?
.
pulse
.
pulseLayer
?
.
isHidden
=
false
...
@@ -372,21 +377,18 @@ extension MotionTransition {
...
@@ -372,21 +377,18 @@ extension MotionTransition {
var
snapshotAnimations
=
[
CABasicAnimation
]()
var
snapshotAnimations
=
[
CABasicAnimation
]()
var
snapshotChildAnimations
=
[
CABasicAnimation
]()
var
snapshotChildAnimations
=
[
CABasicAnimation
]()
snapshotAnimations
.
append
(
Motion
.
position
(
to
:
tv
.
motionPosition
))
let
sizeAnimation
=
Motion
.
size
(
tv
.
bounds
.
size
)
let
sizeAnimation
=
Motion
.
size
(
tv
.
bounds
.
size
)
snapshotAnimations
.
append
(
sizeAnimation
)
let
cornerRadiusAnimation
=
Motion
.
corner
(
radius
:
tv
.
cornerRadius
)
snapshotChildAnimations
.
append
(
sizeAnimation
)
snapshotChildAnimations
.
append
(
Motion
.
position
(
x
:
tv
.
bounds
.
width
/
2
,
y
:
tv
.
bounds
.
height
/
2
))
snapshotAnimations
.
append
(
Motion
.
rotate
(
angle
:
tv
.
motionRotationAngle
))
snapshotAnimations
.
append
(
sizeAnimation
)
snapshotAnimations
.
append
(
cornerRadiusAnimation
)
snapshotAnimations
.
append
(
Motion
.
position
(
to
:
tv
.
motionPosition
))
snapshotAnimations
.
append
(
Motion
.
rotation
(
angle
:
tv
.
motionRotationAngle
))
snapshotAnimations
.
append
(
Motion
.
background
(
color
:
tv
.
backgroundColor
??
.
clear
))
snapshotAnimations
.
append
(
Motion
.
background
(
color
:
tv
.
backgroundColor
??
.
clear
))
let
cornerRadiusAnimation
=
Motion
.
corner
(
radius
:
tv
.
cornerRadius
)
snapshotAnimations
.
append
(
cornerRadiusAnimation
)
snapshotChildAnimations
.
append
(
cornerRadiusAnimation
)
snapshotChildAnimations
.
append
(
cornerRadiusAnimation
)
snapshotChildAnimations
.
append
(
sizeAnimation
)
snapshotChildAnimations
.
append
(
Motion
.
position
(
x
:
tv
.
bounds
.
width
/
2
,
y
:
tv
.
bounds
.
height
/
2
))
let
snapshot
=
fv
.
motionTransitionSnapshot
(
afterUpdates
:
true
)
let
snapshot
=
fv
.
motionTransitionSnapshot
(
afterUpdates
:
true
)
transitionView
.
insertSubview
(
snapshot
,
belowSubview
:
transitionSnapshot
)
transitionView
.
insertSubview
(
snapshot
,
belowSubview
:
transitionSnapshot
)
...
...
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