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
e7710088
Unverified
Commit
e7710088
authored
Jan 17, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: added x and y MotionAnimation enum values
parent
41f34e42
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
35 deletions
+120
-35
Sources/iOS/MotionAnimation.swift
+42
-0
Sources/iOS/MotionTransition.swift
+78
-35
No files found.
Sources/iOS/MotionAnimation.swift
View file @
e7710088
...
@@ -50,6 +50,8 @@ public enum MotionAnimationKeyPath: String {
...
@@ -50,6 +50,8 @@ public enum MotionAnimationKeyPath: String {
case
shadowPath
case
shadowPath
case
opacity
case
opacity
case
zPosition
case
zPosition
case
width
=
"bounds.size.width"
case
height
=
"bounds.size.height"
}
}
public
enum
MotionAnimation
{
public
enum
MotionAnimation
{
...
@@ -76,10 +78,14 @@ public enum MotionAnimation {
...
@@ -76,10 +78,14 @@ public enum MotionAnimation {
case
translateX
(
CGFloat
)
case
translateX
(
CGFloat
)
case
translateY
(
CGFloat
)
case
translateY
(
CGFloat
)
case
translateZ
(
CGFloat
)
case
translateZ
(
CGFloat
)
case
x
(
CGFloat
)
case
y
(
CGFloat
)
case
position
(
x
:
CGFloat
,
y
:
CGFloat
)
case
position
(
x
:
CGFloat
,
y
:
CGFloat
)
case
shadow
(
path
:
CGPath
)
case
shadow
(
path
:
CGPath
)
case
fade
(
CGFloat
)
case
fade
(
CGFloat
)
case
zPosition
(
Int
)
case
zPosition
(
Int
)
case
width
(
CGFloat
)
case
height
(
CGFloat
)
}
}
extension
CALayer
{
extension
CALayer
{
...
@@ -159,11 +165,17 @@ extension CALayer {
...
@@ -159,11 +165,17 @@ extension CALayer {
fileprivate
func
motion
(
delay
:
TimeInterval
,
duration
:
TimeInterval
,
timingFunction
:
MotionAnimationTimingFunction
,
animations
:
[
MotionAnimation
])
{
fileprivate
func
motion
(
delay
:
TimeInterval
,
duration
:
TimeInterval
,
timingFunction
:
MotionAnimationTimingFunction
,
animations
:
[
MotionAnimation
])
{
var
t
=
delay
var
t
=
delay
var
w
:
CGFloat
=
0
var
h
:
CGFloat
=
0
for
v
in
animations
{
for
v
in
animations
{
switch
v
{
switch
v
{
case
let
.
delay
(
time
):
case
let
.
delay
(
time
):
t
=
time
t
=
time
case
let
.
width
(
width
):
w
=
width
case
let
.
height
(
height
):
h
=
height
default
:
break
default
:
break
}
}
}
}
...
@@ -223,6 +235,10 @@ extension CALayer {
...
@@ -223,6 +235,10 @@ extension CALayer {
a
.
append
(
Motion
.
translateY
(
to
:
to
))
a
.
append
(
Motion
.
translateY
(
to
:
to
))
case
let
.
translateZ
(
to
):
case
let
.
translateZ
(
to
):
a
.
append
(
Motion
.
translateZ
(
to
:
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
):
case
let
.
position
(
x
,
y
):
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
a
.
append
(
Motion
.
position
(
to
:
CGPoint
(
x
:
x
,
y
:
y
)))
case
let
.
shadow
(
path
):
case
let
.
shadow
(
path
):
...
@@ -235,6 +251,10 @@ extension CALayer {
...
@@ -235,6 +251,10 @@ extension CALayer {
let
zPosition
=
Motion
.
zPosition
(
index
:
index
)
let
zPosition
=
Motion
.
zPosition
(
index
:
index
)
zPosition
.
fromValue
=
s
.
value
(
forKey
:
MotionAnimationKeyPath
.
zPosition
.
rawValue
)
??
NSNumber
(
integerLiteral
:
0
)
zPosition
.
fromValue
=
s
.
value
(
forKey
:
MotionAnimationKeyPath
.
zPosition
.
rawValue
)
??
NSNumber
(
integerLiteral
:
0
)
a
.
append
(
zPosition
)
a
.
append
(
zPosition
)
case
let
.
width
(
w
):
a
.
append
(
Motion
.
width
(
w
))
case
let
.
height
(
h
):
a
.
append
(
Motion
.
height
(
h
))
default
:
break
default
:
break
}
}
}
}
...
@@ -538,4 +558,26 @@ extension Motion {
...
@@ -538,4 +558,26 @@ extension Motion {
animation
.
toValue
=
NSNumber
(
integerLiteral
:
index
)
animation
.
toValue
=
NSNumber
(
integerLiteral
:
index
)
return
animation
return
animation
}
}
/**
Creates a CABasicaAnimation for the width key path.
- Parameter width: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
width
(
_
width
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
width
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
width
))
return
animation
}
/**
Creates a CABasicaAnimation for the height key path.
- Parameter height: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
height
(
_
height
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
height
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
height
))
return
animation
}
}
}
Sources/iOS/MotionTransition.swift
View file @
e7710088
...
@@ -84,6 +84,7 @@ open class MotionTransitionViewController: UIViewController {
...
@@ -84,6 +84,7 @@ open class MotionTransitionViewController: UIViewController {
when subclassing.
when subclassing.
*/
*/
open
func
prepare
()
{
open
func
prepare
()
{
modalPresentationStyle
=
.
custom
transitioningDelegate
=
transitionDelegate
transitioningDelegate
=
transitionDelegate
}
}
}
}
...
@@ -126,8 +127,26 @@ open class MotionTransitionPresentationController: UIPresentationController {
...
@@ -126,8 +127,26 @@ open class MotionTransitionPresentationController: UIPresentationController {
return
return
}
}
print
(
presentedViewController
)
// for v in presentedViewController.view.subviews {
print
(
"Presented"
)
// if 0 < v.transitionIdentifier.utf16.count {
// print(v.transitionAnimations)
// v.motion(v.transitionAnimations)
// }
// }
presentedViewController
.
transitionCoordinator
?
.
animate
(
alongsideTransition
:
{
(
context
)
in
print
(
"Animating"
)
})
print
(
"presentationTransitionWillBegin"
)
}
open
override
func
presentationTransitionDidEnd
(
_
completed
:
Bool
)
{
print
(
"presentationTransitionDidEnd"
)
}
open
override
var
frameOfPresentedViewInContainerView
:
CGRect
{
return
containerView
?
.
bounds
??
.
zero
}
}
}
}
...
@@ -148,34 +167,7 @@ open class MotionTransitionDelegate: NSObject {
...
@@ -148,34 +167,7 @@ open class MotionTransitionDelegate: NSObject {
@objc(animateTransition:)
@objc(animateTransition:)
open
func
animateTransition
(
using
transitionContext
:
UIViewControllerContextTransitioning
)
{
open
func
animateTransition
(
using
transitionContext
:
UIViewControllerContextTransitioning
)
{
guard
let
tView
=
transitionContext
.
view
(
forKey
:
.
to
)
else
{
return
}
guard
let
tVC
=
transitionContext
.
viewController
(
forKey
:
.
to
)
else
{
return
}
guard
let
fView
=
transitionContext
.
view
(
forKey
:
.
from
)
else
{
return
}
guard
let
fVC
=
transitionContext
.
viewController
(
forKey
:
.
from
)
else
{
return
}
self
.
transitionContext
=
transitionContext
containerView
=
transitionContext
.
containerView
toView
=
tView
toViewController
=
tVC
fromView
=
fView
fromViewController
=
fVC
toViewStartFrame
=
transitionContext
.
initialFrame
(
for
:
toViewController
)
toViewFinalFrame
=
transitionContext
.
finalFrame
(
for
:
toViewController
)
fromViewFinalFrame
=
transitionContext
.
finalFrame
(
for
:
fromViewController
)
}
}
@objc(transitionDuration:)
@objc(transitionDuration:)
...
@@ -198,11 +190,11 @@ extension MotionTransitionDelegate: UIViewControllerTransitioningDelegate {
...
@@ -198,11 +190,11 @@ extension MotionTransitionDelegate: UIViewControllerTransitioningDelegate {
}
}
open
func
interactionControllerForDismissal
(
using
animator
:
UIViewControllerAnimatedTransitioning
)
->
UIViewControllerInteractiveTransitioning
?
{
open
func
interactionControllerForDismissal
(
using
animator
:
UIViewControllerAnimatedTransitioning
)
->
UIViewControllerInteractiveTransitioning
?
{
return
MotionTransitionInteractiveAnimator
()
return
nil
//
MotionTransitionInteractiveAnimator()
}
}
open
func
interactionControllerForPresentation
(
using
animator
:
UIViewControllerAnimatedTransitioning
)
->
UIViewControllerInteractiveTransitioning
?
{
open
func
interactionControllerForPresentation
(
using
animator
:
UIViewControllerAnimatedTransitioning
)
->
UIViewControllerInteractiveTransitioning
?
{
return
MotionTransitionInteractiveAnimator
()
return
nil
//
MotionTransitionInteractiveAnimator()
}
}
public
func
presentationController
(
forPresented
presented
:
UIViewController
,
presenting
:
UIViewController
?,
source
:
UIViewController
)
->
UIPresentationController
?
{
public
func
presentationController
(
forPresented
presented
:
UIViewController
,
presenting
:
UIViewController
?,
source
:
UIViewController
)
->
UIPresentationController
?
{
...
@@ -329,7 +321,58 @@ extension MotionTransitionInteractiveDelegate {
...
@@ -329,7 +321,58 @@ extension MotionTransitionInteractiveDelegate {
open
class
MotionTransitionAnimator
:
MotionTransitionDelegate
,
UIViewControllerAnimatedTransitioning
{
open
class
MotionTransitionAnimator
:
MotionTransitionDelegate
,
UIViewControllerAnimatedTransitioning
{
@objc(animateTransition:)
@objc(animateTransition:)
open
override
func
animateTransition
(
using
transitionContext
:
UIViewControllerContextTransitioning
)
{
open
override
func
animateTransition
(
using
transitionContext
:
UIViewControllerContextTransitioning
)
{
super
.
animateTransition
(
using
:
transitionContext
)
// guard let tView = transitionContext.view(forKey: .to) else {
// return
// }
guard
let
tVC
=
transitionContext
.
viewController
(
forKey
:
.
to
)
else
{
return
}
// guard let fView = transitionContext.view(forKey: .from) else {
// return
// }
guard
let
fVC
=
transitionContext
.
viewController
(
forKey
:
.
from
)
else
{
return
}
self
.
transitionContext
=
transitionContext
containerView
=
transitionContext
.
containerView
// toView = tView
toViewController
=
tVC
// fromView = fView
fromViewController
=
fVC
toViewStartFrame
=
transitionContext
.
initialFrame
(
for
:
toViewController
)
toViewFinalFrame
=
transitionContext
.
finalFrame
(
for
:
toViewController
)
fromViewFinalFrame
=
transitionContext
.
finalFrame
(
for
:
fromViewController
)
var
duration
=
transitionDuration
(
using
:
nil
)
transitionContext
.
containerView
.
addSubview
(
toViewController
.
view
)
for
v
in
toViewController
.
view
.
subviews
{
if
0
<
v
.
transitionIdentifier
.
utf16
.
count
{
for
a
in
v
.
transitionAnimations
{
switch
a
{
case
let
.
duration
(
dur
):
if
dur
>
duration
{
duration
=
dur
}
default
:
break
}
}
v
.
motion
(
v
.
transitionAnimations
)
}
}
Motion
.
delay
(
duration
)
{
transitionContext
.
completeTransition
(
!
transitionContext
.
transitionWasCancelled
)
}
}
}
}
}
open
class
MotionTransitionInteractiveAnimator
:
MotionTransitionInteractiveDelegate
{
open
class
MotionTransitionInteractiveAnimator
:
MotionTransitionInteractiveDelegate
{
...
@@ -355,9 +398,9 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning
...
@@ -355,9 +398,9 @@ open class FadeMotionTransition: NSObject, UIViewControllerAnimatedTransitioning
transitionContext
.
containerView
.
addSubview
(
toView
)
transitionContext
.
containerView
.
addSubview
(
toView
)
UIView
.
animate
(
withDuration
:
transitionDuration
(
using
:
transitionContext
),
UIView
.
animate
(
withDuration
:
transitionDuration
(
using
:
transitionContext
),
animations
:
{
_
in
animations
:
{
_
in
toView
.
alpha
=
1
toView
.
alpha
=
1
fromView
.
alpha
=
0
fromView
.
alpha
=
0
})
{
_
in
})
{
_
in
transitionContext
.
completeTransition
(
!
transitionContext
.
transitionWasCancelled
)
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