Skip to content

Commit 26950e6

Browse files
committed
Handling the transition of a plain viewcontroller
1 parent ef30ef2 commit 26950e6

File tree

6 files changed

+119
-27
lines changed

6 files changed

+119
-27
lines changed

AMWaveTransition/AMWaveTransition.m

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,37 +104,52 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
104104
if ([fromVC respondsToSelector:@selector(visibleCells)]) {
105105
[[fromVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) {
106106
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * self.maxDelay;
107-
void (^animation)() = ^{
108-
[obj setTransform:CGAffineTransformMakeTranslation(-delta, 0)];
109-
[obj setAlpha:0];
110-
};
111-
void (^completion)(BOOL) = ^(BOOL finished){
112-
[obj setTransform:CGAffineTransformIdentity];
113-
};
114-
if (self.transitionType == AMWaveTransitionTypeSubtle) {
115-
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
116-
} else {
117-
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
118-
}
107+
[self hideView:obj withDelay:delay andDelta:-delta];
119108
}];
109+
} else {
110+
// The controller has no table view, let's animate it gracefully
111+
[self hideView:fromVC.view withDelay:0 andDelta:-delta];
120112
}
121-
113+
122114
if ([toVC respondsToSelector:@selector(visibleCells)]) {
123115
[[toVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) {
124-
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * self.maxDelay;
125-
[obj setTransform:CGAffineTransformMakeTranslation(delta, 0)];
126-
void (^animation)() = ^{
127-
[obj setTransform:CGAffineTransformIdentity];
128-
[obj setAlpha:1];
129-
};
130-
if (self.transitionType == AMWaveTransitionTypeSubtle) {
131-
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
132-
} else {
133-
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
134-
}
116+
NSTimeInterval delay = ((float)idx / (float)[[toVC visibleCells] count]) * self.maxDelay;
117+
[self presentView:obj withDelay:delay andDelta:delta];
135118
}];
119+
} else {
120+
[self presentView:toVC.view withDelay:0 andDelta:delta];
136121
}
137122
}];
138123
}
139124

125+
- (void)hideView:(UIView *)view withDelay:(NSTimeInterval)delay andDelta:(float)delta
126+
{
127+
void (^animation)() = ^{
128+
[view setTransform:CGAffineTransformMakeTranslation(delta, 0)];
129+
[view setAlpha:0];
130+
};
131+
void (^completion)(BOOL) = ^(BOOL finished){
132+
[view setTransform:CGAffineTransformIdentity];
133+
};
134+
if (self.transitionType == AMWaveTransitionTypeSubtle) {
135+
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
136+
} else {
137+
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
138+
}
139+
}
140+
141+
- (void)presentView:(UIView *)view withDelay:(NSTimeInterval)delay andDelta:(float)delta
142+
{
143+
[view setTransform:CGAffineTransformMakeTranslation(delta, 0)];
144+
void (^animation)() = ^{
145+
[view setTransform:CGAffineTransformIdentity];
146+
[view setAlpha:1];
147+
};
148+
if (self.transitionType == AMWaveTransitionTypeSubtle) {
149+
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
150+
} else {
151+
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
152+
}
153+
}
154+
140155
@end

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
6509E34D18FF0CEE0054FD6F /* AMWaveViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6509E34C18FF0CEE0054FD6F /* AMWaveViewController.m */; };
11+
65BD291219114A28002AC110 /* ThirdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 65BD291119114A28002AC110 /* ThirdViewController.m */; };
1112
65E0370A18FE6BE200EFA799 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E0370918FE6BE200EFA799 /* Foundation.framework */; };
1213
65E0370C18FE6BE200EFA799 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E0370B18FE6BE200EFA799 /* CoreGraphics.framework */; };
1314
65E0370E18FE6BE200EFA799 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E0370D18FE6BE200EFA799 /* UIKit.framework */; };
@@ -39,6 +40,8 @@
3940
/* Begin PBXFileReference section */
4041
6509E34B18FF0CEE0054FD6F /* AMWaveViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMWaveViewController.h; sourceTree = "<group>"; };
4142
6509E34C18FF0CEE0054FD6F /* AMWaveViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMWaveViewController.m; sourceTree = "<group>"; };
43+
65BD291019114A28002AC110 /* ThirdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThirdViewController.h; sourceTree = "<group>"; };
44+
65BD291119114A28002AC110 /* ThirdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewController.m; sourceTree = "<group>"; };
4245
65E0370618FE6BE200EFA799 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
4346
65E0370918FE6BE200EFA799 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
4447
65E0370B18FE6BE200EFA799 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
@@ -129,6 +132,8 @@
129132
65E0371F18FE6BE200EFA799 /* ViewController.m */,
130133
65E0374218FE6CC200EFA799 /* SecondViewController.h */,
131134
65E0374318FE6CC200EFA799 /* SecondViewController.m */,
135+
65BD291019114A28002AC110 /* ThirdViewController.h */,
136+
65BD291119114A28002AC110 /* ThirdViewController.m */,
132137
65E0372118FE6BE200EFA799 /* Images.xcassets */,
133138
65E0371018FE6BE200EFA799 /* Supporting Files */,
134139
);
@@ -279,6 +284,7 @@
279284
65E0371A18FE6BE200EFA799 /* AppDelegate.m in Sources */,
280285
65E0371618FE6BE200EFA799 /* main.m in Sources */,
281286
6509E34D18FF0CEE0054FD6F /* AMWaveViewController.m in Sources */,
287+
65BD291219114A28002AC110 /* ThirdViewController.m in Sources */,
282288
);
283289
runOnlyForDeploymentPostprocessing = 0;
284290
};

Demo/Demo/Base.lproj/Main.storyboard

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="60y-Ty-eKT">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13C1021" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="60y-Ty-eKT">
33
<dependencies>
44
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
55
</dependencies>
@@ -86,11 +86,11 @@
8686
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
8787
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
8888
<prototypes>
89-
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="cs6-Bw-Gm0" detailTextLabel="oRp-dV-TdZ" imageView="cXG-vo-fPj" rowHeight="68" style="IBUITableViewCellStyleSubtitle" id="0zg-mu-oP0">
89+
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="cs6-Bw-Gm0" detailTextLabel="oRp-dV-TdZ" imageView="cXG-vo-fPj" rowHeight="68" style="IBUITableViewCellStyleSubtitle" id="0zg-mu-oP0">
9090
<rect key="frame" x="0.0" y="22" width="320" height="68"/>
9191
<autoresizingMask key="autoresizingMask"/>
9292
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="0zg-mu-oP0" id="PTD-s3-Qkg">
93-
<rect key="frame" x="0.0" y="0.0" width="320" height="67"/>
93+
<rect key="frame" x="0.0" y="0.0" width="287" height="67"/>
9494
<autoresizingMask key="autoresizingMask"/>
9595
<subviews>
9696
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="cs6-Bw-Gm0">
@@ -113,6 +113,9 @@
113113
</label>
114114
</subviews>
115115
</tableViewCellContentView>
116+
<connections>
117+
<segue destination="VzN-jR-RDO" kind="push" id="CTb-Ii-0ev"/>
118+
</connections>
116119
</tableViewCell>
117120
</prototypes>
118121
<connections>
@@ -138,6 +141,34 @@
138141
</objects>
139142
<point key="canvasLocation" x="1067" y="138"/>
140143
</scene>
144+
<!--Third View Controller-->
145+
<scene sceneID="CkY-lq-y4B">
146+
<objects>
147+
<viewController id="VzN-jR-RDO" customClass="ThirdViewController" sceneMemberID="viewController">
148+
<layoutGuides>
149+
<viewControllerLayoutGuide type="top" id="9o9-Bj-xWY"/>
150+
<viewControllerLayoutGuide type="bottom" id="6Rn-YL-Ypg"/>
151+
</layoutGuides>
152+
<view key="view" contentMode="scaleToFill" id="i7s-se-8cu">
153+
<rect key="frame" x="0.0" y="64" width="320" height="504"/>
154+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
155+
<subviews>
156+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Hello!" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="H7j-na-eoz">
157+
<rect key="frame" x="20" y="20" width="280" height="21"/>
158+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
159+
<fontDescription key="fontDescription" name="GillSans-Light" family="Gill Sans" pointSize="24"/>
160+
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
161+
<nil key="highlightedColor"/>
162+
</label>
163+
</subviews>
164+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
165+
</view>
166+
<navigationItem key="navigationItem" id="e1f-lR-Unb"/>
167+
</viewController>
168+
<placeholder placeholderIdentifier="IBFirstResponder" id="KzL-9H-U6j" userLabel="First Responder" sceneMemberID="firstResponder"/>
169+
</objects>
170+
<point key="canvasLocation" x="1499" y="138"/>
171+
</scene>
141172
<!--Navigation Controller-->
142173
<scene sceneID="ih9-ZR-08m">
143174
<objects>

Demo/Demo/ThirdViewController.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ThirdViewController.h
3+
// Demo
4+
//
5+
// Created by Andrea on 30/04/14.
6+
// Copyright (c) 2014 Fancy Pixel. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface ThirdViewController : UIViewController
12+
13+
@end

Demo/Demo/ThirdViewController.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
//
3+
// ThirdViewController.m
4+
// Demo
5+
//
6+
// Created by Andrea on 30/04/14.
7+
// Copyright (c) 2014 Fancy Pixel. All rights reserved.
8+
//
9+
10+
#import "ThirdViewController.h"
11+
12+
@interface ThirdViewController ()
13+
14+
@end
15+
16+
@implementation ThirdViewController
17+
18+
- (void)viewDidLoad
19+
{
20+
[super viewDidLoad];
21+
22+
[self.view setBackgroundColor:[UIColor clearColor]];
23+
}
24+
25+
@end

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Implement th ```AMWaveTransitioning``` protocol by returning your tableview's vi
6262
}
6363
```
6464

65+
If the view controller you are transitioning to has no table view, don't implement `visibleCells`, the library will handle the transition correctly.
66+
6567
As you can see in the sample project, the best results are obtained by setting the view and the cells' background to ```clearColor```, and setting a background color or a background image to the navigation controller.
6668

6769

0 commit comments

Comments
 (0)