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 {
}
extension
MotionDefaultAnimator
{
/// Cleans the contexts.
func
clean
()
{
for
v
in
viewToContexts
.
values
{
v
.
clean
()
...
...
@@ -65,6 +66,12 @@ extension MotionDefaultAnimator {
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
{
guard
let
state
=
context
[
view
]
else
{
return
false
...
...
@@ -73,6 +80,12 @@ extension MotionDefaultAnimator {
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
{
var
duration
:
TimeInterval
=
0
...
...
@@ -102,12 +115,23 @@ extension MotionDefaultAnimator {
return
duration
}
/**
Moves the view's animation to the given elapsed time.
- Parameter to elapsedTime: A TimeInterval.
*/
func
seek
(
to
elapsedTime
:
TimeInterval
)
{
for
v
in
viewToContexts
.
values
{
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
{
var
duration
:
TimeInterval
=
0
...
...
@@ -119,6 +143,11 @@ extension MotionDefaultAnimator {
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
)
{
guard
let
v
=
viewToContexts
[
view
]
else
{
return
...
...
Sources/Animator/MotionViewPropertyViewContext.swift
View file @
147da727
...
...
@@ -30,38 +30,43 @@ import UIKit
@available(iOS 10, tvOS 10, *)
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
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
resume
(
at
elapsedTime
:
TimeInterval
,
isReversed
:
Bool
)
{
viewPropertyAnimator
?
.
finishAnimation
(
at
:
isReversed
?
.
start
:
.
end
)
}
override
func
seek
(
to
elapsedTime
:
TimeInterval
)
{
viewPropertyAnimator
?
.
pauseAnimation
()
viewPropertyAnimator
?
.
fractionComplete
=
CGFloat
(
elapsedTime
/
duration
)
}
override
func
seek
(
to
elapsedTime
:
TimeInterval
)
{
viewPropertyAnimator
?
.
pauseAnimation
()
viewPropertyAnimator
?
.
fractionComplete
=
CGFloat
(
elapsedTime
/
duration
)
}
override
func
clean
()
{
super
.
clean
()
viewPropertyAnimator
?
.
stopAnimation
(
true
)
viewPropertyAnimator
=
nil
}
override
func
clean
()
{
super
.
clean
()
viewPropertyAnimator
?
.
stopAnimation
(
true
)
viewPropertyAnimator
=
nil
}
override
func
startAnimations
(
isAppearing
:
Bool
)
{
guard
let
visualEffectView
=
snapshot
as?
UIVisualEffectView
else
{
return
}
let
appearedEffect
=
visualEffectView
.
effect
let
disappearedEffect
=
targetState
.
opacity
==
0
?
nil
:
visualEffectView
.
effect
visualEffectView
.
effect
=
isAppearing
?
disappearedEffect
:
appearedEffect
override
func
startAnimations
(
isAppearing
:
Bool
)
{
guard
let
v
=
snapshot
as?
UIVisualEffectView
else
{
return
}
let
appearedEffect
=
v
.
effect
let
disappearedEffect
=
0
==
targetState
.
opacity
?
nil
:
v
.
effect
v
.
effect
=
isAppearing
?
disappearedEffect
:
appearedEffect
duration
=
targetState
.
duration
!
viewPropertyAnimator
=
UIViewPropertyAnimator
(
duration
:
duration
,
curve
:
.
easeInOut
)
{
visualEffectView
.
effect
=
isAppearing
?
appearedEffect
:
disappearedEffect
duration
=
targetState
.
duration
!
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