diff --git a/JTGestureBasedTableViewDemo.xcodeproj/project.pbxproj b/JTGestureBasedTableViewDemo.xcodeproj/project.pbxproj index 001dad0..7712c86 100644 --- a/JTGestureBasedTableViewDemo.xcodeproj/project.pbxproj +++ b/JTGestureBasedTableViewDemo.xcodeproj/project.pbxproj @@ -21,6 +21,8 @@ 52D621A014DF7F1E00400117 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6217E14DF7F1E00400117 /* Foundation.framework */; }; 52D621A814DF7F1E00400117 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 52D621A614DF7F1E00400117 /* InfoPlist.strings */; }; 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 */ /* Begin PBXContainerItemProxy section */ @@ -54,6 +56,9 @@ 52D621A714DF7F1E00400117 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 52D621A914DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JTGestureBasedTableViewDemoTests.h; sourceTree = ""; }; 52D621AA14DF7F1E00400117 /* JTGestureBasedTableViewDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JTGestureBasedTableViewDemoTests.m; sourceTree = ""; }; + 52D621B814DF84A500400117 /* TransformableTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TransformableTableViewCell.h; sourceTree = ""; }; + 52D621B914DF84A500400117 /* TransformableTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TransformableTableViewCell.m; sourceTree = ""; }; + 52D621BB14DF86D600400117 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -61,6 +66,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 52D621BC14DF86D600400117 /* QuartzCore.framework in Frameworks */, 52D6217D14DF7F1E00400117 /* UIKit.framework in Frameworks */, 52D6217F14DF7F1E00400117 /* Foundation.framework in Frameworks */, 52D6218114DF7F1E00400117 /* CoreGraphics.framework in Frameworks */, @@ -83,6 +89,7 @@ 52D6216D14DF7F1E00400117 = { isa = PBXGroup; children = ( + 52D621BB14DF86D600400117 /* QuartzCore.framework */, 52D6218214DF7F1E00400117 /* JTGestureBasedTableViewDemo */, 52D621A314DF7F1E00400117 /* JTGestureBasedTableViewDemoTests */, 52D6217B14DF7F1E00400117 /* Frameworks */, @@ -117,6 +124,8 @@ 52D6218C14DF7F1E00400117 /* AppDelegate.m */, 52D6218E14DF7F1E00400117 /* ViewController.h */, 52D6218F14DF7F1E00400117 /* ViewController.m */, + 52D621B814DF84A500400117 /* TransformableTableViewCell.h */, + 52D621B914DF84A500400117 /* TransformableTableViewCell.m */, 52D6219114DF7F1E00400117 /* ViewController_iPhone.xib */, 52D6219414DF7F1E00400117 /* ViewController_iPad.xib */, 52D6218314DF7F1E00400117 /* Supporting Files */, @@ -264,6 +273,7 @@ 52D6218914DF7F1E00400117 /* main.m in Sources */, 52D6218D14DF7F1E00400117 /* AppDelegate.m in Sources */, 52D6219014DF7F1E00400117 /* ViewController.m in Sources */, + 52D621BA14DF84A500400117 /* TransformableTableViewCell.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -327,7 +337,7 @@ ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 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; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -342,6 +352,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 5.0; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = "1CA8CFA0-0B9D-4AC6-BFFE-A7C2D73369FF"; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/JTGestureBasedTableViewDemo/TransformableTableViewCell.h b/JTGestureBasedTableViewDemo/TransformableTableViewCell.h new file mode 100644 index 0000000..4994a9b --- /dev/null +++ b/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 + +@interface TransformableTableViewCell : UITableViewCell + +@property (nonatomic, assign) CGFloat finishedHeight; + +@end diff --git a/JTGestureBasedTableViewDemo/TransformableTableViewCell.m b/JTGestureBasedTableViewDemo/TransformableTableViewCell.m new file mode 100644 index 0000000..2dd9ecc --- /dev/null +++ b/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 + +@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 diff --git a/JTGestureBasedTableViewDemo/ViewController.m b/JTGestureBasedTableViewDemo/ViewController.m index 5e10b46..fd00a49 100644 --- a/JTGestureBasedTableViewDemo/ViewController.m +++ b/JTGestureBasedTableViewDemo/ViewController.m @@ -7,13 +7,21 @@ // #import "ViewController.h" +#import "TransformableTableViewCell.h" +#import + +@interface ViewController () +@property (nonatomic, strong) NSMutableArray *selectedIndexPaths; +@end @implementation ViewController +@synthesize selectedIndexPaths; #pragma mark - View lifecycle - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { + self.selectedIndexPaths = [NSMutableArray array]; } return self; } @@ -74,12 +82,14 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"MyCell"; - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; + TransformableTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 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.detailTextLabel.text = @" "; return cell; } @@ -87,13 +97,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N #pragma mark UITableViewDelegate - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - if ([[tableView indexPathForSelectedRow] isEqual:indexPath]) { - return 44 * 2; + NSUInteger index = [self.selectedIndexPaths indexOfObject:indexPath]; + if (index != NSNotFound) { + return 88; } - return 44; + return 36; } - (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 endUpdates]; }