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
81b97305
Unverified
Commit
81b97305
authored
Feb 02, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated README
parent
c9b17207
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
80 deletions
+96
-80
README.md
+10
-2
Sources/Info.plist
+1
-1
Sources/MotionAnimation.swift
+15
-0
Sources/MotionTransition.swift
+70
-77
No files found.
README.md
View file @
81b97305
## Welcome to Motion
Seamless animation
and transition
in Swift.
Seamless animation
s and transitions
in Swift.
** Releasing Later Today **
### Documentation
Documentation for using Motion will be released February 3rd 2017.
### Sample
Take a look at a sample
[
Photo Collection
](
https://github.com/CosmicMind/Samples/tree/master/Motion/PhotoCollection
)
project.

## License
...
...
Sources/Info.plist
View file @
81b97305
...
...
@@ -15,7 +15,7 @@
<
k
e
y
>
CFBundlePackageType
<
/k
e
y
>
<
string
>
FMWK
<
/string
>
<
k
e
y
>
CFBundleShortVersionString
<
/k
e
y
>
<
string
>
1.0
<
/string
>
<
string
>
1.0
.0
<
/string
>
<
k
e
y
>
CFBundleVersion
<
/k
e
y
>
<
string
>
$
(
CURRENT_PROJECT_VERSION
)<
/string
>
<
k
e
y
>
NSPrincipalClass
<
/k
e
y
>
...
...
Sources/MotionAnimation.swift
View file @
81b97305
...
...
@@ -325,6 +325,21 @@ extension UIView {
}
}
/// The global position of a view.
open
var
motionPosition
:
CGPoint
{
return
superview
?
.
convert
(
position
,
to
:
nil
)
??
position
}
/// The layer.transform of a view.
open
var
motionTransform
:
CATransform3D
{
get
{
return
layer
.
transform
}
set
(
value
)
{
layer
.
transform
=
value
}
}
/// Computes the scale X axis value of the view.
open
var
motionScaleX
:
CGFloat
{
return
transform
.
a
...
...
Sources/MotionTransition.swift
View file @
81b97305
...
...
@@ -30,34 +30,35 @@
import
UIKit
fileprivate
var
Motion
Transition
InstanceKey
:
UInt8
=
0
fileprivate
var
Motion
Transition
InstanceControllerKey
:
UInt8
=
0
fileprivate
var
MotionInstanceKey
:
UInt8
=
0
fileprivate
var
MotionInstanceControllerKey
:
UInt8
=
0
fileprivate
struct
Motion
Transition
Instance
{
fileprivate
struct
MotionInstance
{
fileprivate
var
identifier
:
String
fileprivate
var
animations
:
[
MotionAnimation
]
}
fileprivate
struct
Motion
Transition
InstanceController
{
fileprivate
struct
MotionInstanceController
{
fileprivate
var
isEnabled
:
Bool
fileprivate
weak
var
delegate
:
MotionDelegate
?
}
extension
UIViewController
:
UIViewControllerTransitioningDelegate
{
/// Motion
Transition
InstanceController Reference.
fileprivate
var
motion
Transition
:
MotionTransi
tionInstanceController
{
/// MotionInstanceController Reference.
fileprivate
var
motion
:
Mo
tionInstanceController
{
get
{
return
AssociatedObject
(
base
:
self
,
key
:
&
Motion
Transition
InstanceControllerKey
)
{
return
Motion
TransitionInstanceController
(
isEnabled
:
false
)
return
AssociatedObject
(
base
:
self
,
key
:
&
MotionInstanceControllerKey
)
{
return
Motion
InstanceController
(
isEnabled
:
false
,
delegate
:
nil
)
}
}
set
(
value
)
{
AssociateObject
(
base
:
self
,
key
:
&
Motion
Transition
InstanceControllerKey
,
value
:
value
)
AssociateObject
(
base
:
self
,
key
:
&
MotionInstanceControllerKey
,
value
:
value
)
}
}
open
var
isMotion
Transition
Enabled
:
Bool
{
open
var
isMotionEnabled
:
Bool
{
get
{
return
motion
Transition
.
isEnabled
return
motion
.
isEnabled
}
set
(
value
)
{
if
value
{
...
...
@@ -65,74 +66,66 @@ extension UIViewController: UIViewControllerTransitioningDelegate {
transitioningDelegate
=
self
}
motionTransition
.
isEnabled
=
value
motion
.
isEnabled
=
value
}
}
open
weak
var
motionDelegate
:
MotionDelegate
?
{
get
{
return
motion
.
delegate
}
set
(
value
)
{
motion
.
delegate
=
value
}
}
}
extension
UIViewController
{
open
func
animationController
(
forPresented
presented
:
UIViewController
,
presenting
:
UIViewController
,
source
:
UIViewController
)
->
UIViewControllerAnimatedTransitioning
?
{
return
isMotion
Transition
Enabled
?
MotionTransition
(
isPresenting
:
true
)
:
nil
return
isMotionEnabled
?
MotionTransition
(
isPresenting
:
true
)
:
nil
}
open
func
animationController
(
forDismissed
dismissed
:
UIViewController
)
->
UIViewControllerAnimatedTransitioning
?
{
return
isMotion
Transition
Enabled
?
MotionTransition
()
:
nil
return
isMotionEnabled
?
MotionTransition
()
:
nil
}
open
func
presentationController
(
forPresented
presented
:
UIViewController
,
presenting
:
UIViewController
?,
source
:
UIViewController
)
->
UIPresentationController
?
{
return
isMotionTransitionEnabled
?
MotionTransitionPresentationController
(
presentedViewController
:
presented
,
presenting
:
presenting
)
:
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
return
isMotionEnabled
?
MotionTransitionPresentationController
(
presentedViewController
:
presented
,
presenting
:
presenting
)
:
nil
}
}
extension
UIView
{
/// The global position of a view.
open
var
motionPosition
:
CGPoint
{
return
superview
?
.
convert
(
position
,
to
:
nil
)
??
position
}
/// MaterialTransitionItem Reference.
fileprivate
var
motion
Transition
:
MotionTransi
tionInstance
{
fileprivate
var
motion
Instance
:
Mo
tionInstance
{
get
{
return
AssociatedObject
(
base
:
self
,
key
:
&
Motion
Transition
InstanceKey
)
{
return
Motion
Transition
Instance
(
identifier
:
""
,
animations
:
[])
return
AssociatedObject
(
base
:
self
,
key
:
&
MotionInstanceKey
)
{
return
MotionInstance
(
identifier
:
""
,
animations
:
[])
}
}
set
(
value
)
{
AssociateObject
(
base
:
self
,
key
:
&
Motion
Transition
InstanceKey
,
value
:
value
)
AssociateObject
(
base
:
self
,
key
:
&
MotionInstanceKey
,
value
:
value
)
}
}
open
var
motion
Transition
Identifier
:
String
{
open
var
motionIdentifier
:
String
{
get
{
return
motion
Transition
.
identifier
return
motion
Instance
.
identifier
}
set
(
value
)
{
motion
Transition
.
identifier
=
value
motion
Instance
.
identifier
=
value
}
}
open
var
motion
Transition
Animations
:
[
MotionAnimation
]
{
open
var
motionAnimations
:
[
MotionAnimation
]
{
get
{
return
motion
Transition
.
animations
return
motion
Instance
.
animations
}
set
(
value
)
{
motion
Transition
.
animations
=
value
motion
Instance
.
animations
=
value
}
}
open
func
motion
TransitionSnapshot
(
afterUpdates
:
Bool
)
->
UIView
{
open
func
motion
Snapshot
(
afterUpdates
:
Bool
,
shouldHide
:
Bool
=
true
)
->
UIView
{
isHidden
=
false
let
oldCornerRadius
=
cornerRadius
...
...
@@ -141,19 +134,19 @@ extension UIView {
let
oldBackgroundColor
=
backgroundColor
backgroundColor
=
.
clear
let
oldTransform
=
t
ransform
transform
=
.
i
dentity
let
oldTransform
=
motionT
ransform
motionTransform
=
CATransform3DI
dentity
let
v
=
snapshotView
(
afterScreenUpdates
:
afterUpdates
)
!
cornerRadius
=
oldCornerRadius
backgroundColor
=
oldBackgroundColor
t
ransform
=
oldTransform
motionT
ransform
=
oldTransform
let
contentView
=
v
.
subviews
.
first
!
contentView
.
cornerRadius
=
cornerRadius
contentView
.
masksToBounds
=
true
v
.
motion
TransitionIdentifier
=
motionTransi
tionIdentifier
v
.
motion
Identifier
=
mo
tionIdentifier
v
.
position
=
motionPosition
v
.
bounds
=
bounds
v
.
cornerRadius
=
cornerRadius
...
...
@@ -169,10 +162,10 @@ extension UIView {
v
.
shadowColor
=
shadowColor
v
.
shadowOffset
=
shadowOffset
v
.
contentMode
=
contentMode
v
.
transform
=
t
ransform
v
.
motionTransform
=
motionT
ransform
v
.
backgroundColor
=
backgroundColor
isHidden
=
tru
e
isHidden
=
shouldHid
e
return
v
}
...
...
@@ -216,6 +209,15 @@ open class MotionTransitionPresentationController: UIPresentationController {
}
}
@objc(MotionDelegate)
public
protocol
MotionDelegate
{
@objc
optional
func
motion
(
transition
:
MotionTransition
,
willTransition
toView
:
UIView
,
fromView
:
UIView
)
@objc
optional
func
motion
(
transition
:
MotionTransition
,
didTransition
toView
:
UIView
,
fromView
:
UIView
)
}
open
class
MotionTransition
:
NSObject
{
open
var
isPresenting
:
Bool
...
...
@@ -271,7 +273,7 @@ open class MotionTransition: NSObject {
open
func
subviews
(
of
view
:
UIView
,
views
:
inout
[
UIView
])
{
for
v
in
view
.
subviews
{
if
0
<
v
.
motion
Transition
Identifier
.
utf16
.
count
{
if
0
<
v
.
motionIdentifier
.
utf16
.
count
{
views
.
append
(
v
)
}
subviews
(
of
:
v
,
views
:
&
views
)
...
...
@@ -321,19 +323,15 @@ extension MotionTransition {
}
fileprivate
func
prepareTransitionSnapshot
()
{
transitionSnapshot
=
fromView
.
motion
TransitionSnapshot
(
afterUpdates
:
tru
e
)
transitionSnapshot
=
fromView
.
motion
Snapshot
(
afterUpdates
:
true
,
shouldHide
:
fals
e
)
transitionSnapshot
.
frame
=
containerView
.
bounds
containerView
.
addSubview
(
transitionSnapshot
)
containerView
.
insertSubview
(
transitionSnapshot
,
aboveSubview
:
fromView
)
}
fileprivate
func
prepareTransitionPairs
()
{
for
from
in
fromSubviews
{
guard
0
<
from
.
motionTransitionIdentifier
.
utf16
.
count
else
{
continue
}
for
to
in
toSubviews
{
guard
to
.
motion
TransitionIdentifier
==
from
.
motionTransi
tionIdentifier
else
{
guard
to
.
motion
Identifier
==
from
.
mo
tionIdentifier
else
{
continue
}
...
...
@@ -348,17 +346,15 @@ extension MotionTransition {
}
fileprivate
func
prepareTransitionBackgroundView
()
{
transitionBackgroundView
.
backgroundColor
=
fromView
.
backgroundColo
r
transitionBackgroundView
.
backgroundColor
=
isPresenting
?
.
clear
:
fromView
.
backgroundColor
??
.
clea
r
transitionBackgroundView
.
frame
=
transitionView
.
bounds
transitionView
.
addSubview
(
transitionBackgroundView
)
}
fileprivate
func
prepareTransitionToView
()
{
if
isPresenting
{
containerView
.
insertSubview
(
toView
,
belowSubview
:
transitionView
)
}
toView
.
isHidden
=
isPresenting
containerView
.
insertSubview
(
toView
,
belowSubview
:
transitionView
)
toView
.
isHidden
=
false
toView
.
updateConstraints
()
toView
.
setNeedsLayout
()
toView
.
layoutIfNeeded
()
...
...
@@ -369,7 +365,6 @@ extension MotionTransition {
addBackgroundMotionAnimation
()
cleanupAnimation
()
hideFromView
()
removeTransitionSnapshot
()
}
}
...
...
@@ -386,19 +381,21 @@ extension MotionTransition {
snapshotAnimations
.
append
(
sizeAnimation
)
snapshotAnimations
.
append
(
cornerRadiusAnimation
)
snapshotAnimations
.
append
(
Motion
.
position
(
to
:
to
.
motionPosition
))
snapshotAnimations
.
append
(
Motion
.
rotation
(
angle
:
to
.
motionRotationAngle
))
snapshotAnimations
.
append
(
Motion
.
transform
(
transform
:
to
.
motionTransform
))
snapshotAnimations
.
append
(
Motion
.
background
(
color
:
to
.
backgroundColor
??
.
clear
))
snapshotChildAnimations
.
append
(
cornerRadiusAnimation
)
snapshotChildAnimations
.
append
(
sizeAnimation
)
snapshotChildAnimations
.
append
(
Motion
.
position
(
x
:
to
.
bounds
.
width
/
2
,
y
:
to
.
bounds
.
height
/
2
))
let
d
=
motionDuration
(
animations
:
to
.
motionTransitionAnimations
)
let
d
=
motionDuration
(
animations
:
to
.
motionAnimations
)
fromViewController
.
motionDelegate
?
.
motion
?(
transition
:
self
,
willTransition
:
toView
,
fromView
:
fromView
)
let
snapshot
=
from
.
motion
Transition
Snapshot
(
afterUpdates
:
true
)
let
snapshot
=
from
.
motionSnapshot
(
afterUpdates
:
true
)
transitionView
.
addSubview
(
snapshot
)
Motion
.
delay
(
motionDelay
(
animations
:
to
.
motion
Transition
Animations
))
{
[
weak
self
,
weak
to
]
in
Motion
.
delay
(
motionDelay
(
animations
:
to
.
motionAnimations
))
{
[
weak
self
,
weak
to
]
in
guard
let
s
=
self
else
{
return
}
...
...
@@ -407,7 +404,7 @@ extension MotionTransition {
return
}
let
tf
=
s
.
motionTimingFunction
(
animations
:
v
.
motion
Transition
Animations
)
let
tf
=
s
.
motionTimingFunction
(
animations
:
v
.
motionAnimations
)
let
snapshotGroup
=
Motion
.
animate
(
group
:
snapshotAnimations
,
duration
:
d
)
snapshotGroup
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
...
...
@@ -426,7 +423,7 @@ extension MotionTransition {
}
fileprivate
func
addBackgroundMotionAnimation
()
{
transitionBackgroundView
.
motion
(
.
backgroundColor
(
toView
.
backgroundColor
??
.
clear
),
.
duration
(
transitionDuration
(
using
:
transitionContext
)))
transitionBackgroundView
.
motion
(
.
backgroundColor
(
isPresenting
?
toView
.
backgroundColor
??
.
clear
:
.
clear
),
.
duration
(
transitionDuration
(
using
:
transitionContext
)))
}
}
...
...
@@ -481,29 +478,24 @@ extension MotionTransition {
return
}
s
.
hide
ToSubviews
()
s
.
show
ToSubviews
()
s
.
clearTransitionView
()
s
.
clearTransitionPairs
()
s
.
completeTransition
()
}
}
fileprivate
func
hideFromView
()
{
Motion
.
delay
(
delay
)
{
[
weak
self
]
in
self
?
.
fromView
.
isHidden
=
true
}
}
fileprivate
func
removeTransitionSnapshot
()
{
Motion
.
delay
(
delay
)
{
[
weak
self
]
in
self
?
.
transitionSnapshot
.
removeFromSuperview
()
}
}
fileprivate
func
hide
ToSubviews
()
{
fileprivate
func
show
ToSubviews
()
{
toSubviews
.
forEach
{
$0
.
isHidden
=
false
}
toView
.
isHidden
=
false
}
fileprivate
func
clearTransitionPairs
()
{
...
...
@@ -518,6 +510,7 @@ extension MotionTransition {
}
fileprivate
func
completeTransition
()
{
fromViewController
.
motionDelegate
?
.
motion
?(
transition
:
self
,
didTransition
:
toView
,
fromView
:
fromView
)
transitionContext
.
completeTransition
(
!
transitionContext
.
transitionWasCancelled
)
}
}
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