Skip to content

Commit

Permalink
- Added paper unfolding demonstration
Browse files Browse the repository at this point in the history
  • Loading branch information
jamztang committed Feb 6, 2012
1 parent a970628 commit ba0a5fd
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 7 deletions.
13 changes: 12 additions & 1 deletion JTGestureBasedTableViewDemo.xcodeproj/project.pbxproj
Expand Up @@ -21,6 +21,8 @@
52D621A014DF7F1E00400117 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6217E14DF7F1E00400117 /* Foundation.framework */; }; 52D621A014DF7F1E00400117 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6217E14DF7F1E00400117 /* Foundation.framework */; };
52D621A814DF7F1E00400117 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 52D621A614DF7F1E00400117 /* InfoPlist.strings */; }; 52D621A814DF7F1E00400117 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 52D621A614DF7F1E00400117 /* InfoPlist.strings */; };
52D621AB14DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 52D621AA14DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.m */; }; 52D621AB14DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 52D621AA14DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.m */; };
52D621BA14DF84A500400117 /* TransformableTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 52D621B914DF84A500400117 /* TransformableTableViewCell.m */; };
52D621BC14DF86D600400117 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D621BB14DF86D600400117 /* QuartzCore.framework */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */


/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -54,13 +56,17 @@
52D621A714DF7F1E00400117 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; 52D621A714DF7F1E00400117 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
52D621A914DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JTGestureBasedTableViewDemoTests.h; sourceTree = "<group>"; }; 52D621A914DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JTGestureBasedTableViewDemoTests.h; sourceTree = "<group>"; };
52D621AA14DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JTGestureBasedTableViewDemoTests.m; sourceTree = "<group>"; }; 52D621AA14DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JTGestureBasedTableViewDemoTests.m; sourceTree = "<group>"; };
52D621B814DF84A500400117 /* TransformableTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TransformableTableViewCell.h; sourceTree = "<group>"; };
52D621B914DF84A500400117 /* TransformableTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TransformableTableViewCell.m; sourceTree = "<group>"; };
52D621BB14DF86D600400117 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */ /* End PBXFileReference section */


/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
52D6217514DF7F1E00400117 /* Frameworks */ = { 52D6217514DF7F1E00400117 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
52D621BC14DF86D600400117 /* QuartzCore.framework in Frameworks */,
52D6217D14DF7F1E00400117 /* UIKit.framework in Frameworks */, 52D6217D14DF7F1E00400117 /* UIKit.framework in Frameworks */,
52D6217F14DF7F1E00400117 /* Foundation.framework in Frameworks */, 52D6217F14DF7F1E00400117 /* Foundation.framework in Frameworks */,
52D6218114DF7F1E00400117 /* CoreGraphics.framework in Frameworks */, 52D6218114DF7F1E00400117 /* CoreGraphics.framework in Frameworks */,
Expand All @@ -83,6 +89,7 @@
52D6216D14DF7F1E00400117 = { 52D6216D14DF7F1E00400117 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
52D621BB14DF86D600400117 /* QuartzCore.framework */,
52D6218214DF7F1E00400117 /* JTGestureBasedTableViewDemo */, 52D6218214DF7F1E00400117 /* JTGestureBasedTableViewDemo */,
52D621A314DF7F1E00400117 /* JTGestureBasedTableViewDemoTests */, 52D621A314DF7F1E00400117 /* JTGestureBasedTableViewDemoTests */,
52D6217B14DF7F1E00400117 /* Frameworks */, 52D6217B14DF7F1E00400117 /* Frameworks */,
Expand Down Expand Up @@ -117,6 +124,8 @@
52D6218C14DF7F1E00400117 /* AppDelegate.m */, 52D6218C14DF7F1E00400117 /* AppDelegate.m */,
52D6218E14DF7F1E00400117 /* ViewController.h */, 52D6218E14DF7F1E00400117 /* ViewController.h */,
52D6218F14DF7F1E00400117 /* ViewController.m */, 52D6218F14DF7F1E00400117 /* ViewController.m */,
52D621B814DF84A500400117 /* TransformableTableViewCell.h */,
52D621B914DF84A500400117 /* TransformableTableViewCell.m */,
52D6219114DF7F1E00400117 /* ViewController_iPhone.xib */, 52D6219114DF7F1E00400117 /* ViewController_iPhone.xib */,
52D6219414DF7F1E00400117 /* ViewController_iPad.xib */, 52D6219414DF7F1E00400117 /* ViewController_iPad.xib */,
52D6218314DF7F1E00400117 /* Supporting Files */, 52D6218314DF7F1E00400117 /* Supporting Files */,
Expand Down Expand Up @@ -264,6 +273,7 @@
52D6218914DF7F1E00400117 /* main.m in Sources */, 52D6218914DF7F1E00400117 /* main.m in Sources */,
52D6218D14DF7F1E00400117 /* AppDelegate.m in Sources */, 52D6218D14DF7F1E00400117 /* AppDelegate.m in Sources */,
52D6219014DF7F1E00400117 /* ViewController.m in Sources */, 52D6219014DF7F1E00400117 /* ViewController.m in Sources */,
52D621BA14DF84A500400117 /* TransformableTableViewCell.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down Expand Up @@ -327,7 +337,7 @@
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)"; ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Keith Li (ZMNYK85DYB)";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
Expand All @@ -342,6 +352,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0; IPHONEOS_DEPLOYMENT_TARGET = 5.0;
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "1CA8CFA0-0B9D-4AC6-BFFE-A7C2D73369FF";
SDKROOT = iphoneos; SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
Expand Down
15 changes: 15 additions & 0 deletions JTGestureBasedTableViewDemo/TransformableTableViewCell.h
@@ -0,0 +1,15 @@
//
// TransformableTableViewCell.h
// JTGestureBasedTableViewDemo
//
// Created by James Tang on 2/6/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TransformableTableViewCell : UITableViewCell

@property (nonatomic, assign) CGFloat finishedHeight;

@end
73 changes: 73 additions & 0 deletions JTGestureBasedTableViewDemo/TransformableTableViewCell.m
@@ -0,0 +1,73 @@
//
// TransformableTableViewCell.m
// JTGestureBasedTableViewDemo
//
// Created by James Tang on 2/6/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "TransformableTableViewCell.h"
#import <QuartzCore/QuartzCore.h>

@implementation TransformableTableViewCell

@synthesize finishedHeight;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code

[self addObserver:self forKeyPath:@"frame"
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:nil];


CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1/500.f;
[self.contentView.layer setSublayerTransform:transform];


self.textLabel.layer.anchorPoint = CGPointMake(0.5, 0.0);
self.textLabel.clipsToBounds = NO;

self.detailTextLabel.layer.anchorPoint = CGPointMake(0.5, 1.0);
self.detailTextLabel.clipsToBounds = NO;
self.selectionStyle = UITableViewCellSelectionStyleNone;
}
return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"frame"]) {

CGFloat fraction = self.frame.size.height / self.finishedHeight;

CATransform3D transform = CATransform3DMakeRotation((M_PI / 2) - asinf(fraction), -1, 0, 0);
[self.textLabel.layer setTransform:transform];
[self.detailTextLabel.layer setTransform:CATransform3DMakeRotation((M_PI / 2) - asinf(fraction), 1, 0, 0)];
}
}

- (void)layoutSubviews {
[super layoutSubviews];

CGFloat fraction = 1 / (self.frame.size.height / self.finishedHeight);

self.textLabel.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
self.detailTextLabel.backgroundColor = [UIColor colorWithWhite:0.6 alpha:1];

CGFloat labelHeight = self.contentView.frame.size.height/2*fraction;
self.textLabel.frame = CGRectMake(0, 0, self.contentView.frame.size.width, labelHeight);
self.detailTextLabel.frame = CGRectMake(0,self.contentView.frame.size.height - labelHeight, self.contentView.frame.size.width, labelHeight);
}

@end
29 changes: 23 additions & 6 deletions JTGestureBasedTableViewDemo/ViewController.m
Expand Up @@ -7,13 +7,21 @@
// //


#import "ViewController.h" #import "ViewController.h"
#import "TransformableTableViewCell.h"
#import <QuartzCore/QuartzCore.h>

@interface ViewController ()
@property (nonatomic, strong) NSMutableArray *selectedIndexPaths;
@end


@implementation ViewController @implementation ViewController
@synthesize selectedIndexPaths;


#pragma mark - View lifecycle #pragma mark - View lifecycle


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.selectedIndexPaths = [NSMutableArray array];
} }
return self; return self;
} }
Expand Down Expand Up @@ -74,26 +82,35 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"MyCell"; static NSString *cellIdentifier = @"MyCell";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; TransformableTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) { if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell = [[TransformableTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
cell.finishedHeight = 88;
} }

cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
cell.detailTextLabel.text = @" ";


return cell; return cell;
} }


#pragma mark UITableViewDelegate #pragma mark UITableViewDelegate


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[tableView indexPathForSelectedRow] isEqual:indexPath]) { NSUInteger index = [self.selectedIndexPaths indexOfObject:indexPath];
return 44 * 2; if (index != NSNotFound) {
return 88;
} }
return 44; return 36;
} }


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger index = [self.selectedIndexPaths indexOfObject:indexPath];
if (index != NSNotFound) {
[self.selectedIndexPaths removeObjectAtIndex:index];
} else {
[self.selectedIndexPaths addObject:indexPath];
}
[tableView beginUpdates]; [tableView beginUpdates];
[tableView endUpdates]; [tableView endUpdates];
} }
Expand Down

0 comments on commit ba0a5fd

Please sign in to comment.