Skip to content

Commit

Permalink
Handling the transition of a plain viewcontroller
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamazz committed Apr 30, 2014
1 parent ef30ef2 commit 26950e6
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 27 deletions.
63 changes: 39 additions & 24 deletions AMWaveTransition/AMWaveTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,37 +104,52 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
if ([fromVC respondsToSelector:@selector(visibleCells)]) {
[[fromVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) {
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * self.maxDelay;
void (^animation)() = ^{
[obj setTransform:CGAffineTransformMakeTranslation(-delta, 0)];
[obj setAlpha:0];
};
void (^completion)(BOOL) = ^(BOOL finished){
[obj setTransform:CGAffineTransformIdentity];
};
if (self.transitionType == AMWaveTransitionTypeSubtle) {
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
} else {
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
}
[self hideView:obj withDelay:delay andDelta:-delta];
}];
} else {
// The controller has no table view, let's animate it gracefully
[self hideView:fromVC.view withDelay:0 andDelta:-delta];
}

if ([toVC respondsToSelector:@selector(visibleCells)]) {
[[toVC visibleCells] enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL *stop) {
NSTimeInterval delay = ((float)idx / (float)[[fromVC visibleCells] count]) * self.maxDelay;
[obj setTransform:CGAffineTransformMakeTranslation(delta, 0)];
void (^animation)() = ^{
[obj setTransform:CGAffineTransformIdentity];
[obj setAlpha:1];
};
if (self.transitionType == AMWaveTransitionTypeSubtle) {
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
} else {
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
}
NSTimeInterval delay = ((float)idx / (float)[[toVC visibleCells] count]) * self.maxDelay;
[self presentView:obj withDelay:delay andDelta:delta];
}];
} else {
[self presentView:toVC.view withDelay:0 andDelta:delta];
}
}];
}

- (void)hideView:(UIView *)view withDelay:(NSTimeInterval)delay andDelta:(float)delta
{
void (^animation)() = ^{
[view setTransform:CGAffineTransformMakeTranslation(delta, 0)];
[view setAlpha:0];
};
void (^completion)(BOOL) = ^(BOOL finished){
[view setTransform:CGAffineTransformIdentity];
};
if (self.transitionType == AMWaveTransitionTypeSubtle) {
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
} else {
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:completion];
}
}

- (void)presentView:(UIView *)view withDelay:(NSTimeInterval)delay andDelta:(float)delta
{
[view setTransform:CGAffineTransformMakeTranslation(delta, 0)];
void (^animation)() = ^{
[view setTransform:CGAffineTransformIdentity];
[view setAlpha:1];
};
if (self.transitionType == AMWaveTransitionTypeSubtle) {
[UIView animateWithDuration:self.duration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
} else {
[UIView animateWithDuration:self.duration delay:delay usingSpringWithDamping:0.75 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:animation completion:nil];
}
}

@end
6 changes: 6 additions & 0 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
6509E34D18FF0CEE0054FD6F /* AMWaveViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6509E34C18FF0CEE0054FD6F /* AMWaveViewController.m */; };
65BD291219114A28002AC110 /* ThirdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 65BD291119114A28002AC110 /* ThirdViewController.m */; };
65E0370A18FE6BE200EFA799 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E0370918FE6BE200EFA799 /* Foundation.framework */; };
65E0370C18FE6BE200EFA799 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E0370B18FE6BE200EFA799 /* CoreGraphics.framework */; };
65E0370E18FE6BE200EFA799 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65E0370D18FE6BE200EFA799 /* UIKit.framework */; };
Expand Down Expand Up @@ -39,6 +40,8 @@
/* Begin PBXFileReference section */
6509E34B18FF0CEE0054FD6F /* AMWaveViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMWaveViewController.h; sourceTree = "<group>"; };
6509E34C18FF0CEE0054FD6F /* AMWaveViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMWaveViewController.m; sourceTree = "<group>"; };
65BD291019114A28002AC110 /* ThirdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThirdViewController.h; sourceTree = "<group>"; };
65BD291119114A28002AC110 /* ThirdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewController.m; sourceTree = "<group>"; };
65E0370618FE6BE200EFA799 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
65E0370918FE6BE200EFA799 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
65E0370B18FE6BE200EFA799 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -129,6 +132,8 @@
65E0371F18FE6BE200EFA799 /* ViewController.m */,
65E0374218FE6CC200EFA799 /* SecondViewController.h */,
65E0374318FE6CC200EFA799 /* SecondViewController.m */,
65BD291019114A28002AC110 /* ThirdViewController.h */,
65BD291119114A28002AC110 /* ThirdViewController.m */,
65E0372118FE6BE200EFA799 /* Images.xcassets */,
65E0371018FE6BE200EFA799 /* Supporting Files */,
);
Expand Down Expand Up @@ -279,6 +284,7 @@
65E0371A18FE6BE200EFA799 /* AppDelegate.m in Sources */,
65E0371618FE6BE200EFA799 /* main.m in Sources */,
6509E34D18FF0CEE0054FD6F /* AMWaveViewController.m in Sources */,
65BD291219114A28002AC110 /* ThirdViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
37 changes: 34 additions & 3 deletions Demo/Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<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">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
Expand Down Expand Up @@ -86,11 +86,11 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<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">
<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">
<rect key="frame" x="0.0" y="22" width="320" height="68"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="0zg-mu-oP0" id="PTD-s3-Qkg">
<rect key="frame" x="0.0" y="0.0" width="320" height="67"/>
<rect key="frame" x="0.0" y="0.0" width="287" height="67"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="cs6-Bw-Gm0">
Expand All @@ -113,6 +113,9 @@
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="VzN-jR-RDO" kind="push" id="CTb-Ii-0ev"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
Expand All @@ -138,6 +141,34 @@
</objects>
<point key="canvasLocation" x="1067" y="138"/>
</scene>
<!--Third View Controller-->
<scene sceneID="CkY-lq-y4B">
<objects>
<viewController id="VzN-jR-RDO" customClass="ThirdViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="9o9-Bj-xWY"/>
<viewControllerLayoutGuide type="bottom" id="6Rn-YL-Ypg"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="i7s-se-8cu">
<rect key="frame" x="0.0" y="64" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<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">
<rect key="frame" x="20" y="20" width="280" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="GillSans-Light" family="Gill Sans" pointSize="24"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" id="e1f-lR-Unb"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="KzL-9H-U6j" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1499" y="138"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="ih9-ZR-08m">
<objects>
Expand Down
13 changes: 13 additions & 0 deletions Demo/Demo/ThirdViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ThirdViewController.h
// Demo
//
// Created by Andrea on 30/04/14.
// Copyright (c) 2014 Fancy Pixel. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ThirdViewController : UIViewController

@end
25 changes: 25 additions & 0 deletions Demo/Demo/ThirdViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

//
// ThirdViewController.m
// Demo
//
// Created by Andrea on 30/04/14.
// Copyright (c) 2014 Fancy Pixel. All rights reserved.
//

#import "ThirdViewController.h"

@interface ThirdViewController ()

@end

@implementation ThirdViewController

- (void)viewDidLoad
{
[super viewDidLoad];

[self.view setBackgroundColor:[UIColor clearColor]];
}

@end
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Implement th ```AMWaveTransitioning``` protocol by returning your tableview's vi
}
```

If the view controller you are transitioning to has no table view, don't implement `visibleCells`, the library will handle the transition correctly.

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.


Expand Down

0 comments on commit 26950e6

Please sign in to comment.