-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update transition examples with TransitionTween.
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
Showing
8 changed files
with
186 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.