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
ee27036f
Unverified
Commit
ee27036f
authored
Jan 18, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: updated rotate function in Motion library
parent
8836c5d4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
166 additions
and
15 deletions
+166
-15
Sources/iOS/MotionAnimation.swift
+114
-3
Sources/iOS/MotionTransition.swift
+52
-12
No files found.
Sources/iOS/MotionAnimation.swift
View file @
ee27036f
...
@@ -204,7 +204,10 @@ extension CALayer {
...
@@ -204,7 +204,10 @@ extension CALayer {
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
.
rotate
(
angle
):
a
.
append
(
Motion
.
rotate
(
angle
:
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
):
case
let
.
rotateX
(
angle
):
a
.
append
(
Motion
.
rotateX
(
angle
:
angle
))
a
.
append
(
Motion
.
rotateX
(
angle
:
angle
))
case
let
.
rotateY
(
angle
):
case
let
.
rotateY
(
angle
):
...
@@ -287,11 +290,119 @@ extension UIView {
...
@@ -287,11 +290,119 @@ extension UIView {
}
}
open
func
motion
(
_
animations
:
MotionAnimation
...
)
{
open
func
motion
(
_
animations
:
MotionAnimation
...
)
{
layer
.
motion
(
animations
)
motion
(
animations
)
}
}
open
func
motion
(
_
animations
:
[
MotionAnimation
])
{
open
func
motion
(
_
animations
:
[
MotionAnimation
])
{
layer
.
motion
(
animations
)
motion
(
delay
:
0
,
duration
:
0.25
,
timingFunction
:
.
easeInEaseOut
,
animations
:
animations
)
}
fileprivate
func
motion
(
delay
:
TimeInterval
,
duration
:
TimeInterval
,
timingFunction
:
MotionAnimationTimingFunction
,
animations
:
[
MotionAnimation
])
{
var
t
=
delay
var
w
:
CGFloat
=
0
var
h
:
CGFloat
=
0
for
v
in
animations
{
switch
v
{
case
let
.
delay
(
time
):
t
=
time
case
let
.
width
(
width
):
w
=
width
case
let
.
height
(
height
):
h
=
height
default
:
break
}
}
Motion
.
delay
(
t
)
{
[
weak
self
]
in
guard
let
s
=
self
else
{
return
}
var
a
=
[
CABasicAnimation
]()
var
tf
=
timingFunction
var
d
=
duration
for
v
in
animations
{
switch
v
{
case
let
.
timingFunction
(
timingFunction
):
tf
=
timingFunction
case
let
.
duration
(
duration
):
d
=
duration
case
let
.
custom
(
animation
):
a
.
append
(
animation
)
case
let
.
backgroundColor
(
color
):
a
.
append
(
Motion
.
background
(
color
:
color
))
case
let
.
corners
(
radius
):
a
.
append
(
Motion
.
corner
(
radius
:
radius
))
case
let
.
transform
(
transform
):
a
.
append
(
Motion
.
transform
(
transform
:
transform
))
case
let
.
rotate
(
angle
):
let
rotate
=
Motion
.
rotate
(
angle
:
angle
)
let
radians
=
CGFloat
(
atan2f
(
Float
(
s
.
transform
.
b
),
Float
(
s
.
transform
.
a
)))
rotate
.
fromValue
=
(
radians
*
(
180
/
CGFloat
(
M_PI
)))
as
NSNumber
a
.
append
(
rotate
)
case
let
.
rotateX
(
angle
):
a
.
append
(
Motion
.
rotateX
(
angle
:
angle
))
case
let
.
rotateY
(
angle
):
a
.
append
(
Motion
.
rotateY
(
angle
:
angle
))
case
let
.
rotateZ
(
angle
):
a
.
append
(
Motion
.
rotateZ
(
angle
:
angle
))
case
let
.
spin
(
rotations
):
a
.
append
(
Motion
.
spin
(
rotations
:
rotations
))
case
let
.
spinX
(
rotations
):
a
.
append
(
Motion
.
spinX
(
rotations
:
rotations
))
case
let
.
spinY
(
rotations
):
a
.
append
(
Motion
.
spinY
(
rotations
:
rotations
))
case
let
.
spinZ
(
rotations
):
a
.
append
(
Motion
.
spinZ
(
rotations
:
rotations
))
case
let
.
scale
(
to
):
a
.
append
(
Motion
.
scale
(
to
:
to
))
case
let
.
scaleX
(
to
):
a
.
append
(
Motion
.
scaleX
(
to
:
to
))
case
let
.
scaleY
(
to
):
a
.
append
(
Motion
.
scaleY
(
to
:
to
))
case
let
.
scaleZ
(
to
):
a
.
append
(
Motion
.
scaleZ
(
to
:
to
))
case
let
.
translate
(
x
,
y
):
a
.
append
(
Motion
.
translate
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
case
let
.
translateX
(
to
):
a
.
append
(
Motion
.
translateX
(
to
:
to
))
case
let
.
translateY
(
to
):
a
.
append
(
Motion
.
translateY
(
to
:
to
))
case
let
.
translateZ
(
to
):
a
.
append
(
Motion
.
translateZ
(
to
:
to
))
case
let
.
x
(
x
):
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
x
+
w
/
2
,
y
:
s
.
position
.
y
)))
case
let
.
y
(
y
):
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
s
.
position
.
x
,
y
:
y
+
h
/
2
)))
case
let
.
position
(
x
,
y
):
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
case
let
.
shadow
(
path
):
a
.
append
(
Motion
.
shadow
(
path
:
path
))
case
let
.
fade
(
opacity
):
let
fade
=
Motion
.
fade
(
opacity
:
opacity
)
fade
.
fromValue
=
s
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
opacity
.
rawValue
)
??
NSNumber
(
floatLiteral
:
1
)
a
.
append
(
fade
)
case
let
.
zPosition
(
index
):
let
zPosition
=
Motion
.
zPosition
(
index
:
index
)
zPosition
.
fromValue
=
s
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
zPosition
.
rawValue
)
??
NSNumber
(
integerLiteral
:
0
)
a
.
append
(
zPosition
)
case
let
.
width
(
w
):
a
.
append
(
Motion
.
width
(
w
))
case
let
.
height
(
h
):
a
.
append
(
Motion
.
height
(
h
))
default
:
break
}
}
let
g
=
Motion
.
animate
(
group
:
a
,
duration
:
d
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
g
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
tf
)
s
.
animate
(
g
)
}
}
}
}
}
...
...
Sources/iOS/MotionTransition.swift
View file @
ee27036f
...
@@ -128,14 +128,14 @@ open class MotionTransitionPresentationController: UIPresentationController {
...
@@ -128,14 +128,14 @@ open class MotionTransitionPresentationController: UIPresentationController {
}
}
presentedViewController
.
transitionCoordinator
?
.
animate
(
alongsideTransition
:
{
(
context
)
in
presentedViewController
.
transitionCoordinator
?
.
animate
(
alongsideTransition
:
{
(
context
)
in
print
(
"Animating"
)
//
print("Animating")
})
})
print
(
"presentationTransitionWillBegin"
)
//
print("presentationTransitionWillBegin")
}
}
open
override
func
presentationTransitionDidEnd
(
_
completed
:
Bool
)
{
open
override
func
presentationTransitionDidEnd
(
_
completed
:
Bool
)
{
print
(
"presentationTransitionDidEnd"
)
//
print("presentationTransitionDidEnd")
}
}
open
override
func
dismissalTransitionWillBegin
()
{
open
override
func
dismissalTransitionWillBegin
()
{
...
@@ -144,14 +144,14 @@ open class MotionTransitionPresentationController: UIPresentationController {
...
@@ -144,14 +144,14 @@ open class MotionTransitionPresentationController: UIPresentationController {
}
}
presentedViewController
.
transitionCoordinator
?
.
animate
(
alongsideTransition
:
{
(
context
)
in
presentedViewController
.
transitionCoordinator
?
.
animate
(
alongsideTransition
:
{
(
context
)
in
print
(
"Animating"
)
//
print("Animating")
})
})
print
(
"dismissalTransitionWillBegin"
)
//
print("dismissalTransitionWillBegin")
}
}
open
override
func
dismissalTransitionDidEnd
(
_
completed
:
Bool
)
{
open
override
func
dismissalTransitionDidEnd
(
_
completed
:
Bool
)
{
print
(
"dismissalTransitionDidEnd"
)
//
print("dismissalTransitionDidEnd")
}
}
open
override
var
frameOfPresentedViewInContainerView
:
CGRect
{
open
override
var
frameOfPresentedViewInContainerView
:
CGRect
{
...
@@ -185,7 +185,7 @@ open class MotionTransitionDelegate: NSObject {
...
@@ -185,7 +185,7 @@ open class MotionTransitionDelegate: NSObject {
}
}
open
func
animationEnded
(
_
transitionCompleted
:
Bool
)
{
open
func
animationEnded
(
_
transitionCompleted
:
Bool
)
{
print
(
"MotionTransitionAnimator"
,
#function
)
//
print("MotionTransitionAnimator", #function)
}
}
}
}
...
@@ -291,7 +291,7 @@ open class MotionTransitionInteractiveDelegate: UIPercentDrivenInteractiveTransi
...
@@ -291,7 +291,7 @@ open class MotionTransitionInteractiveDelegate: UIPercentDrivenInteractiveTransi
}
}
open
func
animationEnded
(
_
transitionCompleted
:
Bool
)
{
open
func
animationEnded
(
_
transitionCompleted
:
Bool
)
{
print
(
"MotionTransitionAnimator"
,
#function
)
//
print("MotionTransitionAnimator", #function)
}
}
}
}
...
@@ -427,21 +427,57 @@ open class MotionTransitionPresentedAnimator: MotionTransitionDelegate, UIViewCo
...
@@ -427,21 +427,57 @@ open class MotionTransitionPresentedAnimator: MotionTransitionDelegate, UIViewCo
if
0
<
v
.
transitionIdentifier
.
utf16
.
count
{
if
0
<
v
.
transitionIdentifier
.
utf16
.
count
{
for
v2
in
fromViewController
.
view
.
subviews
{
for
v2
in
fromViewController
.
view
.
subviews
{
if
v
.
transitionIdentifier
==
v2
.
transitionIdentifier
{
if
v
.
transitionIdentifier
==
v2
.
transitionIdentifier
{
var
d
:
TimeInterval
=
0
var
a
=
[
CABasicAnimation
]()
var
tf
=
MotionAnimationTimingFunction
.
easeInEaseOut
for
ta
in
v
.
transitionAnimations
{
for
ta
in
v
.
transitionAnimations
{
switch
ta
{
switch
ta
{
case
let
.
delay
(
time
):
case
let
.
delay
(
time
):
if
time
>
delay
{
if
time
>
delay
{
delay
=
time
delay
=
time
}
}
d
=
time
case
let
.
duration
(
time
):
case
let
.
duration
(
time
):
if
time
>
duration
{
if
time
>
duration
{
duration
=
time
duration
=
time
}
}
case
let
.
timingFunction
(
timingFunction
):
tf
=
timingFunction
case
let
.
rotate
(
angle
):
let
rotate
=
Motion
.
rotate
(
angle
:
angle
)
let
radians
=
CGFloat
(
atan2f
(
Float
(
v2
.
transform
.
b
),
Float
(
v2
.
transform
.
a
)))
rotate
.
fromValue
=
v2
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
a
.
append
(
rotate
)
case
let
.
backgroundColor
(
color
):
a
.
append
(
Motion
.
background
(
color
:
color
))
case
let
.
corners
(
radius
):
a
.
append
(
Motion
.
corner
(
radius
:
radius
))
case
let
.
x
(
x
):
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
x
+
v
.
bounds
.
width
/
2
,
y
:
v
.
position
.
y
)))
case
let
.
y
(
y
):
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
v
.
position
.
x
,
y
:
y
+
v
.
bounds
.
height
/
2
)))
case
let
.
position
(
x
,
y
):
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
case
let
.
shadow
(
path
):
a
.
append
(
Motion
.
shadow
(
path
:
path
))
case
let
.
width
(
w
):
a
.
append
(
Motion
.
width
(
w
))
case
let
.
height
(
h
):
a
.
append
(
Motion
.
height
(
h
))
default
:
break
default
:
break
}
}
}
}
v
.
motion
(
v
.
transitionAnimations
)
Motion
.
delay
(
d
)
{
let
g
=
Motion
.
animate
(
group
:
a
,
duration
:
duration
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
g
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
tf
)
v
.
animate
(
g
)
}
}
}
}
}
}
}
...
@@ -511,6 +547,11 @@ open class MotionTransitionDismissedAnimator: MotionTransitionDelegate, UIViewCo
...
@@ -511,6 +547,11 @@ open class MotionTransitionDismissedAnimator: MotionTransitionDelegate, UIViewCo
}
}
case
let
.
timingFunction
(
timingFunction
):
case
let
.
timingFunction
(
timingFunction
):
tf
=
timingFunction
tf
=
timingFunction
case
let
.
rotate
(
angle
):
let
radians
=
CGFloat
(
atan2f
(
Float
(
v2
.
transform
.
b
),
Float
(
v2
.
transform
.
a
)))
let
rotate
=
Motion
.
rotate
(
angle
:
radians
*
180
/
CGFloat
(
M_PI
))
rotate
.
fromValue
=
v
.
layer
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
rotation
.
rawValue
)
a
.
append
(
rotate
)
case
let
.
backgroundColor
(
color
):
case
let
.
backgroundColor
(
color
):
a
.
append
(
Motion
.
background
(
color
:
v2
.
backgroundColor
??
.
clear
))
a
.
append
(
Motion
.
background
(
color
:
v2
.
backgroundColor
??
.
clear
))
case
let
.
corners
(
radius
):
case
let
.
corners
(
radius
):
...
@@ -544,7 +585,6 @@ open class MotionTransitionDismissedAnimator: MotionTransitionDelegate, UIViewCo
...
@@ -544,7 +585,6 @@ open class MotionTransitionDismissedAnimator: MotionTransitionDelegate, UIViewCo
}
}
}
}
print
(
"DELAY"
,
delay
+
duration
)
Motion
.
delay
(
delay
+
duration
)
{
Motion
.
delay
(
delay
+
duration
)
{
transitionContext
.
completeTransition
(
!
transitionContext
.
transitionWasCancelled
)
transitionContext
.
completeTransition
(
!
transitionContext
.
transitionWasCancelled
)
}
}
...
@@ -587,7 +627,7 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning
...
@@ -587,7 +627,7 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning
}
}
open
func
animationEnded
(
_
transitionCompleted
:
Bool
)
{
open
func
animationEnded
(
_
transitionCompleted
:
Bool
)
{
print
(
"FadeMotionTransition ANIMATION ENDED"
)
//
print("FadeMotionTransition ANIMATION ENDED")
}
}
}
}
...
@@ -662,7 +702,7 @@ open class SlideMotionTransition: NSObject, UIViewControllerAnimatedTransitionin
...
@@ -662,7 +702,7 @@ open class SlideMotionTransition: NSObject, UIViewControllerAnimatedTransitionin
}
}
open
func
animationEnded
(
_
transitionCompleted
:
Bool
)
{
open
func
animationEnded
(
_
transitionCompleted
:
Bool
)
{
print
(
"SlideMotionTransition ANIMATION ENDED"
)
//
print("SlideMotionTransition ANIMATION ENDED")
}
}
}
}
...
...
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