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
147da727
Unverified
Commit
147da727
authored
Jun 05, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reworked the MotionViewPropertyViewContext class
parent
1bce1231
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
28 deletions
+62
-28
Sources/Animator/MotionDefaultAnimator.swift
+29
-0
Sources/Animator/MotionViewPropertyViewContext.swift
+33
-28
No files found.
Sources/Animator/MotionDefaultAnimator.swift
View file @
147da727
...
@@ -56,6 +56,7 @@ extension MotionDefaultAnimator {
...
@@ -56,6 +56,7 @@ extension MotionDefaultAnimator {
}
}
extension
MotionDefaultAnimator
{
extension
MotionDefaultAnimator
{
/// Cleans the contexts.
func
clean
()
{
func
clean
()
{
for
v
in
viewToContexts
.
values
{
for
v
in
viewToContexts
.
values
{
v
.
clean
()
v
.
clean
()
...
@@ -65,6 +66,12 @@ extension MotionDefaultAnimator {
...
@@ -65,6 +66,12 @@ extension MotionDefaultAnimator {
insertToViewFirst
=
false
insertToViewFirst
=
false
}
}
/**
A function that determines if a view can be animated.
- Parameter view: A UIView.
- Parameter isAppearing: A boolean that determines whether the
view is appearing.
*/
func
canAnimate
(
view
:
UIView
,
isAppearing
:
Bool
)
->
Bool
{
func
canAnimate
(
view
:
UIView
,
isAppearing
:
Bool
)
->
Bool
{
guard
let
state
=
context
[
view
]
else
{
guard
let
state
=
context
[
view
]
else
{
return
false
return
false
...
@@ -73,6 +80,12 @@ extension MotionDefaultAnimator {
...
@@ -73,6 +80,12 @@ extension MotionDefaultAnimator {
return
T
.
canAnimate
(
view
:
view
,
state
:
state
,
isAppearing
:
isAppearing
)
return
T
.
canAnimate
(
view
:
view
,
state
:
state
,
isAppearing
:
isAppearing
)
}
}
/**
Animates the from-views to the to-views.
- Parameter fromViews: An Array of UIViews.
- Parameter toViews: An Array of UIViews.
- Returns: A TimeInterval.
*/
func
animate
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
->
TimeInterval
{
func
animate
(
fromViews
:
[
UIView
],
toViews
:
[
UIView
])
->
TimeInterval
{
var
duration
:
TimeInterval
=
0
var
duration
:
TimeInterval
=
0
...
@@ -102,12 +115,23 @@ extension MotionDefaultAnimator {
...
@@ -102,12 +115,23 @@ extension MotionDefaultAnimator {
return
duration
return
duration
}
}
/**
Moves the view's animation to the given elapsed time.
- Parameter to elapsedTime: A TimeInterval.
*/
func
seek
(
to
elapsedTime
:
TimeInterval
)
{
func
seek
(
to
elapsedTime
:
TimeInterval
)
{
for
v
in
viewToContexts
.
values
{
for
v
in
viewToContexts
.
values
{
v
.
seek
(
to
:
elapsedTime
)
v
.
seek
(
to
:
elapsedTime
)
}
}
}
}
/**
Resumes the animation with a given elapsed time and
optional reversed boolean.
- Parameter at elapsedTime: A TimeInterval.
- Parameter isReversed: A boolean to reverse the animation
or not.
*/
func
resume
(
at
elapsedTime
:
TimeInterval
,
isReversed
:
Bool
)
->
TimeInterval
{
func
resume
(
at
elapsedTime
:
TimeInterval
,
isReversed
:
Bool
)
->
TimeInterval
{
var
duration
:
TimeInterval
=
0
var
duration
:
TimeInterval
=
0
...
@@ -119,6 +143,11 @@ extension MotionDefaultAnimator {
...
@@ -119,6 +143,11 @@ extension MotionDefaultAnimator {
return
duration
return
duration
}
}
/**
Applies the given state to the given view.
- Parameter state: A MotionTargetState.
- Parameter to view: A UIView.
*/
func
apply
(
state
:
MotionTargetState
,
to
view
:
UIView
)
{
func
apply
(
state
:
MotionTargetState
,
to
view
:
UIView
)
{
guard
let
v
=
viewToContexts
[
view
]
else
{
guard
let
v
=
viewToContexts
[
view
]
else
{
return
return
...
...
Sources/Animator/MotionViewPropertyViewContext.swift
View file @
147da727
...
@@ -30,38 +30,43 @@ import UIKit
...
@@ -30,38 +30,43 @@ import UIKit
@available(iOS 10, tvOS 10, *)
@available(iOS 10, tvOS 10, *)
internal
class
MotionViewPropertyViewContext
:
MotionAnimatorViewContext
{
internal
class
MotionViewPropertyViewContext
:
MotionAnimatorViewContext
{
/// A reference to the UIViewPropertyAnimator.
fileprivate
var
viewPropertyAnimator
:
UIViewPropertyAnimator
?
override
class
func
canAnimate
(
view
:
UIView
,
state
:
MotionTargetState
,
isAppearing
:
Bool
)
->
Bool
{
return
view
is
UIVisualEffectView
&&
nil
!=
state
.
opacity
}
var
viewPropertyAnimator
:
UIViewPropertyAnimator
?
override
func
resume
(
at
elapsedTime
:
TimeInterval
,
isReversed
:
Bool
)
{
viewPropertyAnimator
?
.
finishAnimation
(
at
:
isReversed
?
.
start
:
.
end
)
override
class
func
canAnimate
(
view
:
UIView
,
state
:
MotionTargetState
,
isAppearing
:
Bool
)
->
Bool
{
}
return
view
is
UIVisualEffectView
&&
state
.
opacity
!=
nil
}
override
func
resume
(
elapsedTime
:
TimeInterval
,
isReversed
:
Bool
)
{
viewPropertyAnimator
?
.
finishAnimation
(
at
:
isReversed
?
.
start
:
.
end
)
}
override
func
seek
(
to
elapsedTime
:
TimeInterval
)
{
override
func
seek
(
to
elapsedTime
:
TimeInterval
)
{
viewPropertyAnimator
?
.
pauseAnimation
()
viewPropertyAnimator
?
.
pauseAnimation
()
viewPropertyAnimator
?
.
fractionComplete
=
CGFloat
(
elapsedTime
/
duration
)
viewPropertyAnimator
?
.
fractionComplete
=
CGFloat
(
elapsedTime
/
duration
)
}
}
override
func
clean
()
{
override
func
clean
()
{
super
.
clean
()
super
.
clean
()
viewPropertyAnimator
?
.
stopAnimation
(
true
)
viewPropertyAnimator
?
.
stopAnimation
(
true
)
viewPropertyAnimator
=
nil
viewPropertyAnimator
=
nil
}
}
override
func
startAnimations
(
isAppearing
:
Bool
)
{
override
func
startAnimations
(
isAppearing
:
Bool
)
{
guard
let
visualEffectView
=
snapshot
as?
UIVisualEffectView
else
{
return
}
guard
let
v
=
snapshot
as?
UIVisualEffectView
else
{
let
appearedEffect
=
visualEffectView
.
effect
return
let
disappearedEffect
=
targetState
.
opacity
==
0
?
nil
:
visualEffectView
.
effect
}
visualEffectView
.
effect
=
isAppearing
?
disappearedEffect
:
appearedEffect
let
appearedEffect
=
v
.
effect
let
disappearedEffect
=
0
==
targetState
.
opacity
?
nil
:
v
.
effect
v
.
effect
=
isAppearing
?
disappearedEffect
:
appearedEffect
duration
=
targetState
.
duration
!
duration
=
targetState
.
duration
!
viewPropertyAnimator
=
UIViewPropertyAnimator
(
duration
:
duration
,
curve
:
.
easeInOut
)
{
visualEffectView
.
effect
=
isAppearing
?
appearedEffect
:
disappearedEffect
viewPropertyAnimator
=
UIViewPropertyAnimator
(
duration
:
duration
,
curve
:
.
easeInOut
)
{
v
.
effect
=
isAppearing
?
appearedEffect
:
disappearedEffect
}
viewPropertyAnimator
?
.
startAnimation
()
}
}
viewPropertyAnimator
!.
startAnimation
()
}
}
}
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