Skip to content

Commit

Permalink
Update transition examples with TransitionTween.
Browse files Browse the repository at this point in the history
Reviewers: markwei, O2 Material Motion, O4 Material Motion Apple platform reviewers

Reviewed By: markwei, O2 Material Motion, O4 Material Motion Apple platform reviewers

Subscribers: markwei

Tags: #material_motion

Differential Revision: http://codereview.cc/D1892
  • Loading branch information
Jeff Verkoeyen committed Nov 18, 2016
1 parent cf1acf2 commit 36db601
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 117 deletions.
3 changes: 1 addition & 2 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
abstract_target 'MaterialMotionTransitions' do
pod 'MaterialMotionRuntime', "~> 6.0"
pod 'MaterialMotionCoreAnimation', "~> 2.0"
pod 'MaterialMotionCoreAnimationTransitions'
pod 'CatalogByConvention'

pod 'MaterialMotionTransitions', :path => './'
Expand Down
9 changes: 6 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ PODS:
- CatalogByConvention (2.0.0)
- MaterialMotionCoreAnimation (2.0.0):
- MaterialMotionRuntime (~> 6.0)
- MaterialMotionCoreAnimationTransitions (1.0.0):
- MaterialMotionCoreAnimation (~> 2.0)
- MaterialMotionTransitions (~> 1.0)
- MaterialMotionRuntime (6.0.0)
- MaterialMotionTransitions (1.1.0):
- MaterialMotionRuntime (~> 6.0)

DEPENDENCIES:
- CatalogByConvention
- MaterialMotionCoreAnimation (~> 2.0)
- MaterialMotionRuntime (~> 6.0)
- MaterialMotionCoreAnimationTransitions
- MaterialMotionTransitions (from `./`)

EXTERNAL SOURCES:
Expand All @@ -19,9 +21,10 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
CatalogByConvention: be55c2263132e4f9f59299ac8a528ee8715b3275
MaterialMotionCoreAnimation: fc8f32e641c242a7ff40e78248b238f3954c5e75
MaterialMotionCoreAnimationTransitions: abdf7c2c34c2e1831cd82d819f15d006e7e3483e
MaterialMotionRuntime: 89cb395df1ce02134fc67a16b42dc4492b6c514c
MaterialMotionTransitions: b731df47f90a7c8ccc60de1f61446b9f31d08065

PODFILE CHECKSUM: cdc0f1ed86fa9fd611697995ea3a7cd36ff586bf
PODFILE CHECKSUM: 91eb5b3a8aed9ab76bfd57112bc55ea53e83d55a

COCOAPODS: 1.1.1
48 changes: 0 additions & 48 deletions examples/FadeInExample.swift

This file was deleted.

19 changes: 8 additions & 11 deletions examples/FadeInTransitionDirector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
limitations under the License.
*/

import UIKit
import MaterialMotionTransitions
import MaterialMotionCoreAnimation
import MaterialMotionCoreAnimationTransitions

class FadeInTransitionDirector: NSObject, TransitionDirector {

Expand All @@ -26,14 +25,12 @@ class FadeInTransitionDirector: NSObject, TransitionDirector {
}

func setUp() {
let animation = Tween("opacity", duration: transition.window.duration)
if transition.direction == .forward {
animation.from = NSNumber(value: 0)
animation.to = NSNumber(value: 1)
} else {
animation.from = NSNumber(value: 1)
animation.to = NSNumber(value: 0)
}
transition.runtime.addPlan(animation, to: transition.foreViewController.view)
let fadeIn = TransitionTween("opacity",
transition: transition,
segment: .init(position: 0, length: 1),
back: NSNumber(value: 0),
fore: NSNumber(value: 1))
fadeIn.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.runtime.addPlan(fadeIn, to: transition.foreViewController.view.layer)
}
}
38 changes: 38 additions & 0 deletions examples/SlideInTransitionDirector.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2016-present The Material Motion Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import MaterialMotionTransitions
import MaterialMotionCoreAnimationTransitions

class SlideInTransitionDirector: NSObject, TransitionDirector {

let transition: Transition
required init(transition: Transition) {
self.transition = transition
}

func setUp() {
let midY = Double(transition.foreViewController.view.layer.position.y)
let height = Double(transition.foreViewController.view.bounds.height)
let slide = TransitionTween("position.y",
transition: transition,
segment: .init(position: 0, length: 1),
back: NSNumber(value: midY + height),
fore: NSNumber(value: midY))
slide.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
transition.runtime.addPlan(slide, to: transition.foreViewController.view.layer)
}
}
76 changes: 76 additions & 0 deletions examples/TransitionExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright 2016-present The Material Motion Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import UIKit
import MaterialMotionCoreAnimation
import MaterialMotionTransitions

let transitionDirectors: [TransitionDirector.Type] = [
FadeInTransitionDirector.self,
SlideInTransitionDirector.self
]
let cellIdentifier = "directorCell"

class ShowNavController: UINavigationController {
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
}
}

class FadeInExampleViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellIdentifier)

view.backgroundColor = .white
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return transitionDirectors.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
cell.textLabel?.text = NSStringFromClass(transitionDirectors[indexPath.row])
return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let directorClass = transitionDirectors[indexPath.row]

let viewController = UIViewController()
viewController.view.backgroundColor = .white
viewController.title = NSStringFromClass(directorClass)
let navigationController = ShowNavController(rootViewController: viewController)

viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(
title: "Back",
style: .done,
target: self,
action: #selector(didTapBack)
)

navigationController.mdm_transitionController.directorClass = directorClass

present(navigationController, animated: true)
}

func didTapBack() {
dismiss(animated: true)
}
}
Loading

0 comments on commit 36db601

Please sign in to comment.