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 {
case
duration
(
TimeInterval
)
case
custom
(
CABasicAnimation
)
case
backgroundColor
(
UIColor
)
case
corners
(
CGFloat
)
case
corner
Radiu
s
(
CGFloat
)
case
transform
(
CATransform3D
)
case
rotat
e
(
Double
)
case
rotat
eX
(
Double
)
case
rotat
eY
(
Double
)
case
rotat
eZ
(
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
rotat
ionAngle
(
CGFloat
)
case
rotat
ionAngleX
(
CGFloat
)
case
rotat
ionAngleY
(
CGFloat
)
case
rotat
ionAngleZ
(
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
translate
(
x
:
CGFloat
,
y
:
CGFloat
)
case
translateX
(
CGFloat
)
case
translateY
(
CGFloat
)
...
...
@@ -243,19 +243,19 @@ extension CALayer {
a
.
append
(
animation
)
case
let
.
backgroundColor
(
color
):
a
.
append
(
Motion
.
background
(
color
:
color
))
case
let
.
corners
(
radius
):
case
let
.
corner
Radiu
s
(
radius
):
a
.
append
(
Motion
.
corner
(
radius
:
radius
))
case
let
.
transform
(
transform
):
a
.
append
(
Motion
.
transform
(
transform
:
transform
))
case
let
.
rotate
(
angle
):
let
rotate
=
Motion
.
rotat
e
(
angle
:
angle
)
case
let
.
rotat
ionAngl
e
(
angle
):
let
rotate
=
Motion
.
rotat
ion
(
angle
:
angle
)
a
.
append
(
rotate
)
case
let
.
rotateX
(
angle
):
a
.
append
(
Motion
.
rotat
e
X
(
angle
:
angle
))
case
let
.
rotateY
(
angle
):
a
.
append
(
Motion
.
rotat
e
Y
(
angle
:
angle
))
case
let
.
rotateZ
(
angle
):
a
.
append
(
Motion
.
rotat
e
Z
(
angle
:
angle
))
case
let
.
rotat
ionAngl
eX
(
angle
):
a
.
append
(
Motion
.
rotat
ion
X
(
angle
:
angle
))
case
let
.
rotat
ionAngl
eY
(
angle
):
a
.
append
(
Motion
.
rotat
ion
Y
(
angle
:
angle
))
case
let
.
rotat
ionAngl
eZ
(
angle
):
a
.
append
(
Motion
.
rotat
ion
Z
(
angle
:
angle
))
case
let
.
spin
(
rotations
):
a
.
append
(
Motion
.
spin
(
rotations
:
rotations
))
case
let
.
spinX
(
rotations
):
...
...
@@ -316,8 +316,13 @@ extension CALayer: CAAnimationDelegate {}
extension
UIView
{
/// Computes the rotation of the view.
open
var
motionRotationAngle
:
Double
{
return
Double
(
atan2f
(
Float
(
transform
.
b
),
Float
(
transform
.
a
)))
*
180
/
M_PI
open
var
motionRotationAngle
:
CGFloat
{
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.
...
...
@@ -413,133 +418,133 @@ extension Motion {
/**
Creates a CABasicAnimation for the transform.rotation key path.
- Parameter angle: An optional
Double
.
- Parameter angle: An optional
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
rotat
e
(
angle
:
Double
)
->
CABasicAnimation
{
public
static
func
rotat
ion
(
angle
:
CGFloat
)
->
CABasicAnimation
{
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
}
/**
Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter angle: An optional
Double
.
- Parameter angle: An optional
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
rotat
eX
(
angle
:
Double
)
->
CABasicAnimation
{
public
static
func
rotat
ionX
(
angle
:
CGFloat
)
->
CABasicAnimation
{
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
}
/**
Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter angle: An optional
Double
.
- Parameter angle: An optional
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
rotat
eY
(
angle
:
Double
)
->
CABasicAnimation
{
public
static
func
rotat
ionY
(
angle
:
CGFloat
)
->
CABasicAnimation
{
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
}
/**
Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter angle: An optional
Double
.
- Parameter angle: An optional
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
rotat
eZ
(
angle
:
Double
)
->
CABasicAnimation
{
public
static
func
rotat
ionZ
(
angle
:
CGFloat
)
->
CABasicAnimation
{
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
}
/**
Creates a CABasicAnimation for the transform.rotation key path.
- Parameter rotations: An optional
Double
.
- Parameter rotations: An optional
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
spin
(
rotations
:
Double
)
->
CABasicAnimation
{
public
static
func
spin
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
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
}
/**
Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter rotations: An optional
Double
.
- Parameter rotations: An optional
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
spinX
(
rotations
:
Double
)
->
CABasicAnimation
{
public
static
func
spinX
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
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
}
/**
Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter rotations: An optional
Double
.
- Parameter rotations: An optional
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
spinY
(
rotations
:
Double
)
->
CABasicAnimation
{
public
static
func
spinY
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
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
}
/**
Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter rotations: An optional
Double
.
- Parameter rotations: An optional
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
spinZ
(
rotations
:
Double
)
->
CABasicAnimation
{
public
static
func
spinZ
(
rotations
:
CGFloat
)
->
CABasicAnimation
{
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
}
/**
Creates a CABasicAnimation for the transform.scale key path.
- Parameter to scale: A
Double
.
- Parameter to scale: A
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
scale
(
to
scale
:
Double
)
->
CABasicAnimation
{
public
static
func
scale
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
scale
)
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.scale.x key path.
- Parameter to scale: A
Double
.
- Parameter to scale: A
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
scaleX
(
to
scale
:
Double
)
->
CABasicAnimation
{
public
static
func
scaleX
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleX
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
scale
)
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.scale.y key path.
- Parameter to scale: A
Double
.
- Parameter to scale: A
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
scaleY
(
to
scale
:
Double
)
->
CABasicAnimation
{
public
static
func
scaleY
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleY
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
scale
)
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.scale.z key path.
- Parameter to scale: A
Double
.
- Parameter to scale: A
CGFloat
.
- Returns: A CABasicAnimation.
*/
public
static
func
scaleZ
(
to
scale
:
Double
)
->
CABasicAnimation
{
public
static
func
scaleZ
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleZ
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
scale
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
scale
)
)
return
animation
}
...
...
Sources/iOS/MotionTransition.swift
View file @
3d538a63
...
...
@@ -84,17 +84,17 @@ extension UIViewController {
}
}
//
extension UIViewController {
//
open func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
//
return isMotionTransitionEnabled ? MotionTransition(isPresenting: operation == .push) : nil
//
}
//
}
//
//
extension UIViewController {
//
open func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
//
return isMotionTransitionEnabled ? MotionTransition() : nil
//
}
//
}
extension
UIViewController
{
open
func
navigationController
(
_
navigationController
:
UINavigationController
,
animationControllerFor
operation
:
UINavigationControllerOperation
,
from
fromVC
:
UIViewController
,
to
toVC
:
UIViewController
)
->
UIViewControllerAnimatedTransitioning
?
{
return
isMotionTransitionEnabled
?
MotionTransition
(
isPresenting
:
operation
==
.
push
)
:
nil
}
}
extension
UIViewController
{
open
func
tabBarController
(
_
tabBarController
:
UITabBarController
,
animationControllerForTransitionFrom
fromVC
:
UIViewController
,
to
toVC
:
UIViewController
)
->
UIViewControllerAnimatedTransitioning
?
{
return
isMotionTransitionEnabled
?
MotionTransition
()
:
nil
}
}
extension
UIView
{
/// The global position of a view.
...
...
@@ -143,11 +143,13 @@ extension UIView {
let
oldBackgroundColor
=
backgroundColor
backgroundColor
=
.
clear
let
oldTransform
=
transform
transform
=
.
identity
let
v
=
snapshotView
(
afterScreenUpdates
:
afterUpdates
)
!
cornerRadius
=
oldCornerRadius
backgroundColor
=
oldBackgroundColor
v
.
backgroundColor
=
oldBackgroundColor
transform
=
oldTransform
let
contentView
=
v
.
subviews
.
first
!
contentView
.
cornerRadius
=
cornerRadius
...
...
@@ -169,7 +171,10 @@ extension UIView {
v
.
shadowColor
=
shadowColor
v
.
shadowOffset
=
shadowOffset
v
.
contentMode
=
contentMode
v
.
layer
.
transform
=
layer
.
transform
v
.
transform
=
transform
v
.
backgroundColor
=
backgroundColor
print
(
motionRotationAngle
)
isHidden
=
true
(
self
as?
Pulseable
)?
.
pulse
.
pulseLayer
?
.
isHidden
=
false
...
...
@@ -372,21 +377,18 @@ extension MotionTransition {
var
snapshotAnimations
=
[
CABasicAnimation
]()
var
snapshotChildAnimations
=
[
CABasicAnimation
]()
snapshotAnimations
.
append
(
Motion
.
position
(
to
:
tv
.
motionPosition
))
let
sizeAnimation
=
Motion
.
size
(
tv
.
bounds
.
size
)
snapshotAnimations
.
append
(
sizeAnimation
)
snapshotChildAnimations
.
append
(
sizeAnimation
)
snapshotChildAnimations
.
append
(
Motion
.
position
(
x
:
tv
.
bounds
.
width
/
2
,
y
:
tv
.
bounds
.
height
/
2
))
snapshotAnimations
.
append
(
Motion
.
rotate
(
angle
:
tv
.
motionRotationAngle
))
let
cornerRadiusAnimation
=
Motion
.
corner
(
radius
:
tv
.
cornerRadius
)
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
))
let
cornerRadiusAnimation
=
Motion
.
corner
(
radius
:
tv
.
cornerRadius
)
snapshotAnimations
.
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
)
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