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
e6a3b296
Unverified
Commit
e6a3b296
authored
Jan 13, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: added MotionTransition properties to UIViews
parent
ca611b57
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
23 deletions
+89
-23
Sources/iOS/CollectionViewController.swift
+6
-1
Sources/iOS/Motion.swift
+46
-6
Sources/iOS/MotionAnimation.swift
+1
-1
Sources/iOS/MotionTransition.swift
+35
-14
Sources/iOS/NavigationController.swift
+1
-1
No files found.
Sources/iOS/CollectionViewController.swift
View file @
e6a3b296
...
@@ -69,6 +69,11 @@ open class CollectionViewController: UIViewController {
...
@@ -69,6 +69,11 @@ open class CollectionViewController: UIViewController {
prepare
()
prepare
()
}
}
open
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
collectionView
.
frame
=
view
.
bounds
}
/**
/**
Prepares the view instance when intialized. When subclassing,
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
it is recommended to override the prepareView method
...
@@ -89,7 +94,7 @@ extension CollectionViewController {
...
@@ -89,7 +94,7 @@ extension CollectionViewController {
fileprivate
func
prepareCollectionView
()
{
fileprivate
func
prepareCollectionView
()
{
collectionView
.
delegate
=
self
collectionView
.
delegate
=
self
collectionView
.
dataSource
=
self
collectionView
.
dataSource
=
self
view
.
layout
(
collectionView
)
.
edges
(
)
view
.
addSubview
(
collectionView
)
}
}
}
}
...
...
Sources/iOS/Motion.swift
View file @
e6a3b296
...
@@ -30,8 +30,48 @@
...
@@ -30,8 +30,48 @@
import
UIKit
import
UIKit
@objc(AnimationFillMode)
/// A memory reference to the MotionIdentifier instance for UIView extensions.
public
enum
AnimationFillMode
:
Int
{
fileprivate
var
MotionIdentifierKey
:
UInt8
=
0
fileprivate
struct
MotionTransitionItem
{
fileprivate
var
identifier
:
String
fileprivate
var
animations
:
[
MotionAnimation
]
}
extension
UIView
{
/// MaterialLayer Reference.
fileprivate
var
motionTransitionItem
:
MotionTransitionItem
{
get
{
return
AssociatedObject
(
base
:
self
,
key
:
&
MotionIdentifierKey
)
{
return
MotionTransitionItem
(
identifier
:
""
,
animations
:
[])
}
}
set
(
value
)
{
AssociateObject
(
base
:
self
,
key
:
&
MotionIdentifierKey
,
value
:
value
)
}
}
open
var
motionIdentifier
:
String
{
get
{
return
motionTransitionItem
.
identifier
}
set
(
value
)
{
motionTransitionItem
.
identifier
=
value
}
}
open
var
motionAnimations
:
[
MotionAnimation
]
{
get
{
return
motionTransitionItem
.
animations
}
set
(
value
)
{
motionTransitionItem
.
animations
=
value
}
}
}
@objc(MotionAnimationFillMode)
public
enum
MotionAnimationFillMode
:
Int
{
case
forwards
case
forwards
case
backwards
case
backwards
case
both
case
both
...
@@ -39,10 +79,10 @@ public enum AnimationFillMode: Int {
...
@@ -39,10 +79,10 @@ public enum AnimationFillMode: Int {
}
}
/**
/**
Converts the AnimationFillMode enum value to a corresponding String.
Converts the
Motion
AnimationFillMode enum value to a corresponding String.
- Parameter mode: An AnimationFillMode enum value.
- Parameter mode: An
Motion
AnimationFillMode enum value.
*/
*/
public
func
AnimationFillModeToValue
(
mode
:
AnimationFillMode
)
->
String
{
public
func
MotionAnimationFillModeToValue
(
mode
:
Motion
AnimationFillMode
)
->
String
{
switch
mode
{
switch
mode
{
case
.
forwards
:
case
.
forwards
:
return
kCAFillModeForwards
return
kCAFillModeForwards
...
@@ -162,7 +202,7 @@ public struct Motion {
...
@@ -162,7 +202,7 @@ public struct Motion {
*/
*/
public
static
func
animate
(
group
animations
:
[
CAAnimation
],
timingFunction
:
MotionAnimationTimingFunction
=
.
easeInEaseOut
,
duration
:
CFTimeInterval
=
0.5
)
->
CAAnimationGroup
{
public
static
func
animate
(
group
animations
:
[
CAAnimation
],
timingFunction
:
MotionAnimationTimingFunction
=
.
easeInEaseOut
,
duration
:
CFTimeInterval
=
0.5
)
->
CAAnimationGroup
{
let
group
=
CAAnimationGroup
()
let
group
=
CAAnimationGroup
()
group
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
group
.
fillMode
=
Motion
AnimationFillModeToValue
(
mode
:
.
forwards
)
group
.
isRemovedOnCompletion
=
false
group
.
isRemovedOnCompletion
=
false
group
.
animations
=
animations
group
.
animations
=
animations
group
.
duration
=
duration
group
.
duration
=
duration
...
...
Sources/iOS/MotionAnimation.swift
View file @
e6a3b296
...
@@ -220,7 +220,7 @@ extension CALayer {
...
@@ -220,7 +220,7 @@ extension CALayer {
}
}
let
g
=
Motion
.
animate
(
group
:
a
,
duration
:
duration
)
let
g
=
Motion
.
animate
(
group
:
a
,
duration
:
duration
)
g
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
fillMode
=
Motion
AnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
g
.
isRemovedOnCompletion
=
false
g
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
timingFunction
)
g
.
timingFunction
=
MotionAnimationTimingFunctionToValue
(
timingFunction
:
timingFunction
)
...
...
Sources/iOS/MotionTransition.swift
View file @
e6a3b296
...
@@ -56,11 +56,11 @@ open class MotionTransitionDelegate: NSObject, UIViewControllerTransitioningDele
...
@@ -56,11 +56,11 @@ open class MotionTransitionDelegate: NSObject, UIViewControllerTransitioningDele
open
class
FadeMotionTransition
:
NSObject
,
UIViewControllerAnimatedTransitioning
{
open
class
FadeMotionTransition
:
NSObject
,
UIViewControllerAnimatedTransitioning
{
open
func
animateTransition
(
using
transitionContext
:
UIViewControllerContextTransitioning
)
{
open
func
animateTransition
(
using
transitionContext
:
UIViewControllerContextTransitioning
)
{
guard
let
fromView
=
transitionContext
.
view
(
forKey
:
UITransitionContextViewKey
.
from
)
else
{
guard
let
fromView
=
transitionContext
.
view
(
forKey
:
.
from
)
else
{
return
return
}
}
guard
let
toView
=
transitionContext
.
view
(
forKey
:
UITransitionContextViewKey
.
to
)
else
{
guard
let
toView
=
transitionContext
.
view
(
forKey
:
.
to
)
else
{
return
return
}
}
...
@@ -74,8 +74,7 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning
...
@@ -74,8 +74,7 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning
toView
.
alpha
=
1
toView
.
alpha
=
1
fromView
.
alpha
=
0
fromView
.
alpha
=
0
})
{
_
in
})
{
_
in
let
success
=
!
transitionContext
.
transitionWasCancelled
transitionContext
.
completeTransition
(
!
transitionContext
.
transitionWasCancelled
)
transitionContext
.
completeTransition
(
success
)
}
}
}
}
...
@@ -89,27 +88,49 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning
...
@@ -89,27 +88,49 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning
}
}
open
class
SlideMotionTransition
:
NSObject
,
UIViewControllerAnimatedTransitioning
{
open
class
SlideMotionTransition
:
NSObject
,
UIViewControllerAnimatedTransitioning
{
var
operation
:
UINavigationControllerOperation
init
(
operation
:
UINavigationControllerOperation
)
{
self
.
operation
=
operation
}
open
func
animateTransition
(
using
transitionContext
:
UIViewControllerContextTransitioning
)
{
open
func
animateTransition
(
using
transitionContext
:
UIViewControllerContextTransitioning
)
{
guard
let
fromView
=
transitionContext
.
view
(
forKey
:
UITransitionContextViewKey
.
from
)
else
{
guard
let
fromView
=
transitionContext
.
view
(
forKey
:
.
from
)
else
{
return
return
}
}
guard
let
toView
=
transitionContext
.
view
(
forKey
:
UITransitionContextViewKey
.
to
)
else
{
guard
let
toView
=
transitionContext
.
view
(
forKey
:
.
to
)
else
{
return
return
}
}
toView
.
y
=
fromView
.
height
if
operation
==
.
push
{
transitionContext
.
containerView
.
addSubview
(
fromView
)
transitionContext
.
containerView
.
addSubview
(
fromView
)
for
v
in
fromView
.
subviews
{
if
0
<
v
.
motionIdentifier
.
utf16
.
count
{
v
.
motion
(
duration
:
0.35
,
animations
:
v
.
motionAnimations
)
}
}
Motion
.
delay
(
time
:
transitionDuration
(
using
:
nil
))
{
transitionContext
.
containerView
.
addSubview
(
toView
)
transitionContext
.
completeTransition
(
!
transitionContext
.
transitionWasCancelled
)
}
}
if
operation
==
.
pop
{
transitionContext
.
containerView
.
addSubview
(
toView
)
transitionContext
.
containerView
.
addSubview
(
toView
)
UIView
.
animate
(
withDuration
:
transitionDuration
(
using
:
transitionContext
),
for
v
in
toView
.
subviews
{
animations
:
{
_
in
if
0
<
v
.
motionIdentifier
.
utf16
.
count
{
toView
.
frame
=
fromView
.
frame
v
.
motion
(
duration
:
0.35
,
animations
:
[
.
scale
(
1
),
.
backgroundColor
(
.
white
)])
// fromView.alpha = 0
}
})
{
_
in
}
let
success
=
!
transitionContext
.
transitionWasCancelled
transitionContext
.
completeTransition
(
success
)
Motion
.
delay
(
time
:
transitionDuration
(
using
:
nil
))
{
transitionContext
.
completeTransition
(
!
transitionContext
.
transitionWasCancelled
)
}
}
}
}
}
...
...
Sources/iOS/NavigationController.swift
View file @
e6a3b296
...
@@ -136,7 +136,7 @@ open class NavigationController: UINavigationController {
...
@@ -136,7 +136,7 @@ open class NavigationController: UINavigationController {
extension
NavigationController
:
UINavigationControllerDelegate
{
extension
NavigationController
:
UINavigationControllerDelegate
{
open
func
navigationController
(
_
navigationController
:
UINavigationController
,
animationControllerFor
operation
:
UINavigationControllerOperation
,
from
fromVC
:
UIViewController
,
to
toVC
:
UIViewController
)
->
UIViewControllerAnimatedTransitioning
?
{
open
func
navigationController
(
_
navigationController
:
UINavigationController
,
animationControllerFor
operation
:
UINavigationControllerOperation
,
from
fromVC
:
UIViewController
,
to
toVC
:
UIViewController
)
->
UIViewControllerAnimatedTransitioning
?
{
return
SlideMotionTransition
()
return
SlideMotionTransition
(
operation
:
operation
)
}
}
}
}
...
...
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