Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 8977b27

Browse files
author
Jeff Verkoeyen
committed
Merge branch 'release-candidate' into stable
2 parents 288c580 + c9ae79b commit 8977b27

34 files changed

+1834
-120
lines changed

.arcconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"arc.feature.start.default": "origin/develop",
1414
"unit.xcode": {
1515
"build": {
16-
"workspace": "MaterialMotionTransitioning.xcworkspace",
16+
"workspace": "Transitioning.xcworkspace",
1717
"scheme": "UnitTests",
1818
"configuration": "Debug",
1919
"destination": "platform=iOS Simulator,name=iPhone 6s"
2020
},
2121
"coverage": {
22-
"product": "MaterialMotionTransitioning.framework/MaterialMotionTransitioning"
22+
"product": "Transitioning.framework/Transitioning"
2323
},
2424
"pre-build": "pod install"
2525
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ before_install:
1010
script:
1111
- set -o pipefail
1212
- arcanist/bin/arc unit --everything --trace
13-
- xcodebuild build -workspace MaterialMotionTransitioning.xcworkspace -scheme Catalog -sdk "iphonesimulator10.1" -destination "name=iPhone 6s,OS=10.1" ONLY_ACTIVE_ARCH=YES | xcpretty -c;
13+
- xcodebuild build -workspace Transitioning.xcworkspace -scheme TransitionsCatalog -sdk "iphonesimulator10.1" -destination "name=iPhone 6s,OS=10.1" ONLY_ACTIVE_ARCH=YES | xcpretty -c;
1414
after_success:
1515
- bash <(curl -s https://codecov.io/bash)

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 1.0.0
2+
3+
Initial release.
4+
5+
Includes support for building simple view controller transitions and transitions that support custom presentation.
6+
7+
## Source changes
8+
9+
* [Clarify the docs for default modal presentation styles. (#4)](https://github.com/material-motion/transitioning-objc/commit/84c23e5f7c490e2a7d299cca6c4046ac4f368551) (featherless)
10+
* [Initial implementation. (#1)](https://github.com/material-motion/transitioning-objc/commit/c1b760455779226ebc9749e06e528d25a6b444bc) (featherless)
11+
12+
## Non-source changes
13+
14+
* [Simplify the frame calculation APIs in the example. (#5)](https://github.com/material-motion/transitioning-objc/commit/8688b045594ee38204744c7c644d4cce58165ec6) (featherless)

Podfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
workspace 'MaterialMotionTransitioning.xcworkspace'
1+
workspace 'Transitioning.xcworkspace'
22
use_frameworks!
33

4-
target "Catalog" do
4+
target "TransitionsCatalog" do
55
pod 'CatalogByConvention'
6-
pod 'MaterialMotionTransitioning', :path => './'
6+
pod 'Transitioning', :path => './'
77

8-
project 'examples/apps/Catalog/Catalog.xcodeproj'
8+
project 'examples/apps/Catalog/TransitionsCatalog.xcodeproj'
99
end
1010

1111
target "UnitTests" do
12-
pod 'MaterialMotionTransitioning', :path => './'
12+
pod 'Transitioning', :path => './'
1313

14-
project 'examples/apps/Catalog/Catalog.xcodeproj'
14+
project 'examples/apps/Catalog/TransitionsCatalog.xcodeproj'
1515
end
1616

1717
post_install do |installer|
1818
installer.pods_project.targets.each do |target|
1919
target.build_configurations.each do |configuration|
2020
configuration.build_settings['SWIFT_VERSION'] = "3.0"
21-
if target.name.start_with?("Material")
21+
if target.name.start_with?("Transitioning")
2222
configuration.build_settings['WARNING_CFLAGS'] ="$(inherited) -Wall -Wcast-align -Wconversion -Werror -Wextra -Wimplicit-atomic-properties -Wmissing-prototypes -Wno-sign-conversion -Wno-unused-parameter -Woverlength-strings -Wshadow -Wstrict-selector-match -Wundeclared-selector -Wunreachable-code"
2323
end
2424
end

Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
PODS:
22
- CatalogByConvention (2.1.1)
3-
- MaterialMotionTransitioning (1.0.0)
3+
- Transitioning (1.0.0)
44

55
DEPENDENCIES:
66
- CatalogByConvention
7-
- MaterialMotionTransitioning (from `./`)
7+
- Transitioning (from `./`)
88

99
EXTERNAL SOURCES:
10-
MaterialMotionTransitioning:
10+
Transitioning:
1111
:path: "./"
1212

1313
SPEC CHECKSUMS:
1414
CatalogByConvention: c3a5319de04250a7cd4649127fcfca5fe3322a43
15-
MaterialMotionTransitioning: 33406d4f24065281e3d2d171bddd794a89e32b7c
15+
Transitioning: d2d2d0609e0acf133f7049ff5ddbe7ca16973f07
1616

17-
PODFILE CHECKSUM: 7343cb186774b759ce5a8ae9aa6df20737289df1
17+
PODFILE CHECKSUM: 1949e62e9d70d554783c0bb931d6b52780775cfb
1818

1919
COCOAPODS: 1.2.1

README.md

Lines changed: 211 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,66 @@
1-
# Material Motion Transitioning
1+
# Transitioning
22

3-
[![Build Status](https://travis-ci.org/material-motion/material-motion-transitioning-objc.svg?branch=develop)](https://travis-ci.org/material-motion/material-motion-transitioning-objc)
4-
[![codecov](https://codecov.io/gh/material-motion/material-motion-transitioning-objc/branch/develop/graph/badge.svg)](https://codecov.io/gh/material-motion/material-motion-transitioning-objc)
5-
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/MaterialMotionTransitioning.svg)](https://cocoapods.org/pods/MaterialMotionTransitioning)
6-
[![Platform](https://img.shields.io/cocoapods/p/MaterialMotionTransitioning.svg)](http://cocoadocs.org/docsets/MaterialMotionTransitioning)
7-
[![Docs](https://img.shields.io/cocoapods/metrics/doc-percent/MaterialMotionTransitioning.svg)](http://cocoadocs.org/docsets/MaterialMotionTransitioning)
3+
> Light-weight API for building UIViewController transitions.
4+
5+
[![Build Status](https://travis-ci.org/material-motion/transitioning-objc.svg?branch=develop)](https://travis-ci.org/material-motion/transitioning-objc)
6+
[![codecov](https://codecov.io/gh/material-motion/transitioning-objc/branch/develop/graph/badge.svg)](https://codecov.io/gh/material-motion/transitioning-objc)
7+
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Transitioning.svg)](https://cocoapods.org/pods/Transitioning)
8+
[![Platform](https://img.shields.io/cocoapods/p/Transitioning.svg)](http://cocoadocs.org/docsets/Transitioning)
9+
[![Docs](https://img.shields.io/cocoapods/metrics/doc-percent/Transitioning.svg)](http://cocoadocs.org/docsets/Transitioning)
10+
11+
This library standardizes the way transitions are built on iOS so that with a single line of code
12+
you can pick the custom transition you want to use:
13+
14+
```swift
15+
let viewController = MyViewController()
16+
viewController.transitionController.transition = CustomTransition()
17+
present(modalViewController, animated: true)
18+
```
19+
20+
```objc
21+
MyViewController *viewController = [[MyViewController alloc] init];
22+
viewController.mdm_transitionController.transition = [[CustomTransition alloc] init];
23+
[self presentViewController:viewController animated:true completion:nil];
24+
```
25+
26+
The easiest way to make a transition with this library is to create a class that conforms to the
27+
`Transition` protocol:
28+
29+
```swift
30+
final class CustomTransition: NSObject, Transition {
31+
func start(with context: TransitionContext) {
32+
CATransaction.begin()
33+
34+
CATransaction.setCompletionBlock {
35+
context.transitionDidEnd()
36+
}
37+
38+
// Add animations...
39+
40+
CATransaction.commit()
41+
}
42+
}
43+
```
44+
45+
```objc
46+
@interface CustomTransition: NSObject <MDMTransition>
47+
@end
48+
49+
@implementation CustomTransition
50+
51+
- (void)startWithContext:(id<MDMTransitionContext>)context {
52+
[CATransaction begin];
53+
[CATransaction setCompletionBlock:^{
54+
[context transitionDidEnd];
55+
}];
56+
57+
// Add animations...
58+
59+
[CATransaction commit];
60+
}
61+
62+
@end
63+
```
864
965
## Installation
1066
@@ -17,9 +73,9 @@
1773
>
1874
> gem install cocoapods
1975
20-
Add `MaterialMotionTransitioning` to your `Podfile`:
76+
Add `Transitioning` to your `Podfile`:
2177
22-
pod 'MaterialMotionTransitioning'
78+
pod 'Transitioning'
2379
2480
Then run the following command:
2581
@@ -29,7 +85,7 @@ Then run the following command:
2985
3086
Import the framework:
3187
32-
@import MaterialMotionTransitioning;
88+
@import Transitioning;
3389
3490
You will now have access to all of the APIs.
3591
@@ -38,25 +94,165 @@ You will now have access to all of the APIs.
3894
Check out a local copy of the repo to access the Catalog application by running the following
3995
commands:
4096
41-
git clone https://github.com/material-motion/material-motion-transitioning-objc.git
42-
cd material-motion-transitioning-objc
97+
git clone https://github.com/material-motion/transitioning-objc.git
98+
cd transitioning-objc
4399
pod install
44-
open MaterialMotionTransitioning.xcworkspace
100+
open Transitioning.xcworkspace
45101
46102
## Guides
47103
48104
1. [Architecture](#architecture)
49-
2. [How to ...](#how-to-...)
105+
2. [How to create a simple transition](#how-to-create-a-simple-transition)
106+
3. [How to customize presentation](#how-to-customize-presentation)
50107
51108
### Architecture
52109
53-
### How to ...
110+
> Background: Transitions in iOS are customized by setting a `transitioningDelegate` on a view
111+
> controller. When a view controller is presented, UIKit will ask the transitioning delegate for an
112+
> animation, interaction, and presentation controller. These controllers are then expected to
113+
> implement the transition's motion.
114+
115+
Transitioning provides a thin layer atop these protocols with the following advantages:
116+
117+
- Every view controller has its own **transition controller**. This encourages choosing the
118+
transition based on the context.
119+
- Transitions are represented in terms of **backward/forward** rather than from/to. When presenting,
120+
we're moving forward. When dismissing, we're moving backward. This makes it easier to refer to
121+
each "side" of a transition consistently.
122+
- Transition objects can customize their behavior by conforming to more `TransitionWith*` protocols.
123+
This protocol-oriented design is more Swift-friendly than a variety of optional methods on a
124+
protocol.
125+
- But most importantly: **this library handles the plumbing, allowing you to focus on the motion**.
126+
127+
### How to create a simple transition
128+
129+
In this guide we'll create scaffolding for a simple transition.
130+
131+
#### Step 1: Define a new Transition type
132+
133+
Transitions must be `NSObject` types that conform to the `Transition` protocol.
134+
135+
The sole method we're expected to implement, `start`, is invoked each time the view controller is
136+
presented or dismissed.
137+
138+
```swift
139+
final class FadeTransition: NSObject, Transition {
140+
func start(with context: TransitionContext) {
141+
142+
}
143+
}
144+
```
145+
146+
#### Step 2: Invoke the completion handler once all animations are complete
147+
148+
If using Core Animation explicitly:
149+
150+
```swift
151+
final class FadeTransition: NSObject, Transition {
152+
func start(with context: TransitionContext) {
153+
CATransaction.begin()
154+
155+
CATransaction.setCompletionBlock {
156+
context.transitionDidEnd()
157+
}
158+
159+
// Your motion...
160+
161+
CATransaction.commit()
162+
}
163+
}
164+
```
165+
166+
If using UIView implicit animations:
167+
168+
```swift
169+
final class FadeTransition: NSObject, Transition {
170+
func start(with context: TransitionContext) {
171+
UIView.animate(withDuration: context.duration, animations: {
172+
// Your motion...
173+
174+
}, completion: { didComplete in
175+
context.transitionDidEnd()
176+
})
177+
}
178+
}
179+
```
180+
181+
#### Step 3: Implement the motion
182+
183+
With the basic scaffolding in place, you can now implement your motion.
184+
185+
### How to customize presentation
186+
187+
You'll customize the presentation of a transition when you need to do any of the following:
188+
189+
- Add views, such as dimming views, that live beyond the lifetime of the transition.
190+
- Change the destination frame of the presented view controller.
191+
192+
#### Step 1: Subclass UIPresentationController
193+
194+
You must subclass UIPresentationController in order to implement your custom behavior. If the user
195+
of your transition can customize any presentation behavior then you'll want to define a custom
196+
initializer.
197+
198+
> Note: Avoid storing the transition context in your presentation controller. Presentation
199+
> controllers live for as long as their associated view controller, while the transition context is
200+
> only valid while a transition is active. Each presentation and dismissal will receive its own
201+
> unique transition context. Storing the context in the presentation controller would keep the
202+
> context alive longer than it's meant to.
203+
204+
Override any `UIPresentationController` methods you'll need in order to implement your motion.
205+
206+
```swift
207+
final class MyPresentationController: UIPresentationController {
208+
}
209+
```
210+
211+
#### Step 2: Implement TransitionWithPresentation on your transition
212+
213+
This ensures that your transition implement the required methods for presentation.
214+
215+
Presentation will only be customized if you return `.custom` from the
216+
`defaultModalPresentationStyle` method and a non-nil `UIPresentationController` subclass from the
217+
`presentationController` method.
218+
219+
```swift
220+
extension VerticalSheetTransition: TransitionWithPresentation {
221+
func defaultModalPresentationStyle() -> UIModalPresentationStyle {
222+
return .custom
223+
}
224+
225+
func presentationController(forPresented presented: UIViewController,
226+
presenting: UIViewController,
227+
source: UIViewController?) -> UIPresentationController? {
228+
return MyPresentationController(presentedViewController: presented, presenting: presenting)
229+
}
230+
}
231+
```
232+
233+
#### Optional Step 3: Implement Transition on your presentation controller
234+
235+
If your presentation controller needs to animate anything, you can conform to the `Transition`
236+
protocol in order to receive a `start` invocation each time a transition begins. The presentation
237+
controller's `start` will be invoked before the transition's `start`.
238+
239+
> Note: It's possible for your presentation controller and your transition to have different ideas
240+
> of when a transition has completed, so consider which object should be responsible for invoking
241+
> `transitionDidEnd`. The `Transition` object is usually the one that calls this method.
242+
243+
```swift
244+
extension MyPresentationController: Transition {
245+
func start(with context: TransitionContext) {
246+
// Your motion...
247+
}
248+
}
249+
```
54250

55251
## Contributing
56252

57253
We welcome contributions!
58254

59-
Check out our [upcoming milestones](https://github.com/material-motion/material-motion-transitioning-objc/milestones).
255+
Check out our [upcoming milestones](https://github.com/material-motion/transitioning-objc/milestones).
60256

61257
Learn more about [our team](https://material-motion.github.io/material-motion/team/),
62258
[our community](https://material-motion.github.io/material-motion/team/community/), and

MaterialMotionTransitioning.podspec renamed to Transitioning.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |s|
2-
s.name = "MaterialMotionTransitioning"
3-
s.summary = "Material Motion Transitioning"
2+
s.name = "Transitioning"
3+
s.summary = "Light-weight API for building UIViewController transitions."
44
s.version = "1.0.0"
55
s.authors = "The Material Motion Authors"
66
s.license = "Apache 2.0"
7-
s.homepage = "https://github.com/material-motion/material-motion-transitioning-objc"
8-
s.source = { :git => "https://github.com/material-motion/material-motion-transitioning-objc.git", :tag => "v" + s.version.to_s }
7+
s.homepage = "https://github.com/material-motion/transitioning-objc"
8+
s.source = { :git => "https://github.com/material-motion/transitioning-objc.git", :tag => "v" + s.version.to_s }
99
s.platform = :ios, "8.0"
1010
s.requires_arc = true
1111

0 commit comments

Comments
 (0)