Skip to content

Commit 38a4e13

Browse files
author
Tom Thorpe
committed
-Updated to add two extra properties cellZoomXOffset and cellZoomYOffset to allow you to customise the initial X and Y positions of the cell before it animates, to allow you to have effects like coming in diagonally from the bottom (like the latest release of the Google+ app does!). The default for both is 0.
-Added a new demo to the demos code (TabThreeViewController) to demonstrate this new property. -Added extra comments to document what each demo does, and the default values of the properties.
1 parent 1152efd commit 38a4e13

9 files changed

+271
-7
lines changed

Diff for: UITableViewZoomController.xcodeproj/project.pbxproj

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
9F7024CF16DBF7F80003B5FA /* TabTwoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9F7024CD16DBF7F80003B5FA /* TabTwoViewController.xib */; };
2424
9F7024D116DBFBE20003B5FA /* FancyCellView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9F7024D016DBFBE20003B5FA /* FancyCellView.xib */; };
2525
9F7024D316DBFC9B0003B5FA /* about-tomthorpelogo.png in Resources */ = {isa = PBXBuildFile; fileRef = 9F7024D216DBFC9B0003B5FA /* about-tomthorpelogo.png */; };
26+
9F80F6E217071D0300EDFFE5 /* TabThreeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F80F6E017071D0300EDFFE5 /* TabThreeViewController.m */; };
27+
9F80F6E317071D0300EDFFE5 /* TabThreeViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9F80F6E117071D0300EDFFE5 /* TabThreeViewController.xib */; };
2628
/* End PBXBuildFile section */
2729

2830
/* Begin PBXFileReference section */
@@ -49,6 +51,9 @@
4951
9F7024CD16DBF7F80003B5FA /* TabTwoViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TabTwoViewController.xib; sourceTree = "<group>"; };
5052
9F7024D016DBFBE20003B5FA /* FancyCellView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FancyCellView.xib; sourceTree = "<group>"; };
5153
9F7024D216DBFC9B0003B5FA /* about-tomthorpelogo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "about-tomthorpelogo.png"; sourceTree = "<group>"; };
54+
9F80F6DF17071D0300EDFFE5 /* TabThreeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TabThreeViewController.h; sourceTree = "<group>"; };
55+
9F80F6E017071D0300EDFFE5 /* TabThreeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TabThreeViewController.m; sourceTree = "<group>"; };
56+
9F80F6E117071D0300EDFFE5 /* TabThreeViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TabThreeViewController.xib; sourceTree = "<group>"; };
5257
/* End PBXFileReference section */
5358

5459
/* Begin PBXFrameworksBuildPhase section */
@@ -146,6 +151,9 @@
146151
9F7024CB16DBF7F80003B5FA /* TabTwoViewController.h */,
147152
9F7024CC16DBF7F80003B5FA /* TabTwoViewController.m */,
148153
9F7024CD16DBF7F80003B5FA /* TabTwoViewController.xib */,
154+
9F80F6DF17071D0300EDFFE5 /* TabThreeViewController.h */,
155+
9F80F6E017071D0300EDFFE5 /* TabThreeViewController.m */,
156+
9F80F6E117071D0300EDFFE5 /* TabThreeViewController.xib */,
149157
9F7024D016DBFBE20003B5FA /* FancyCellView.xib */,
150158
);
151159
path = TableViews;
@@ -211,6 +219,7 @@
211219
9F7024CF16DBF7F80003B5FA /* TabTwoViewController.xib in Resources */,
212220
9F7024D116DBFBE20003B5FA /* FancyCellView.xib in Resources */,
213221
9F7024D316DBFC9B0003B5FA /* about-tomthorpelogo.png in Resources */,
222+
9F80F6E317071D0300EDFFE5 /* TabThreeViewController.xib in Resources */,
214223
);
215224
runOnlyForDeploymentPostprocessing = 0;
216225
};
@@ -226,6 +235,7 @@
226235
9F7024C316DBF7080003B5FA /* TTUITableViewZoomController.m in Sources */,
227236
9F7024C916DBF7E20003B5FA /* TabOneViewController.m in Sources */,
228237
9F7024CE16DBF7F80003B5FA /* TabTwoViewController.m in Sources */,
238+
9F80F6E217071D0300EDFFE5 /* TabThreeViewController.m in Sources */,
229239
);
230240
runOnlyForDeploymentPostprocessing = 0;
231241
};
@@ -343,6 +353,7 @@
343353
9F7024BF16DBF6650003B5FA /* Release */,
344354
);
345355
defaultConfigurationIsVisible = 0;
356+
defaultConfigurationName = Release;
346357
};
347358
/* End XCConfigurationList section */
348359
};

Diff for: UITableViewZoomController/Demo/TTAppDelegate.m

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@
1010

1111
#import "TableViews/TabOneViewController.h"
1212
#import "TableViews/TabTwoViewController.h"
13+
#import "TableViews/TabThreeViewController.h"
1314

1415
@implementation TTAppDelegate
1516

1617
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
1718
{
1819
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
1920
// Override point for customization after application launch.
20-
UIViewController *viewController1, *viewController2;
21+
UIViewController *viewController1, *viewController2, *viewController3;
2122

2223
viewController1 = [[TabOneViewController alloc] init];
2324
viewController1.tabBarItem.title = @"Custom Cells";
2425
viewController2 = [[TabTwoViewController alloc] init];
2526
viewController2.tabBarItem.title = @"Simple Cells";
27+
viewController3 = [[TabThreeViewController alloc] init];
28+
viewController3.tabBarItem.title = @"Custom Offsets";
2629

2730
self.tabBarController = [[UITabBarController alloc] init];
28-
self.tabBarController.viewControllers = @[viewController1, viewController2];
31+
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
2932
self.window.rootViewController = self.tabBarController;
3033
[self.window makeKeyAndVisible];
3134
return YES;

Diff for: UITableViewZoomController/Demo/TableViews/TabOneViewController.m

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
@implementation TabOneViewController
1212

13+
/**
14+
This example uses all the default values of the properties for the table view zoom controller, and doesn't change anything. It uses a custom cell view "FancyCellView" to display an image in each cell rather than text.
15+
*/
1316
-(void)viewDidLoad{
1417
[self.tableView registerNib:[UINib nibWithNibName:@"FancyCellView" bundle:nil]
1518
forCellReuseIdentifier:@"FancyCellView"];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// TabOneViewController.h
3+
// UITableViewZoomController
4+
//
5+
// Created by Thomas Thorpe on 25/02/2013.
6+
// Copyright (c) 2013 Thomas Thorpe. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import "TTUITableViewZoomController.h"
11+
12+
@interface TabThreeViewController : TTUITableViewZoomController
13+
14+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// TabTwoViewController.m
3+
// UITableViewZoomController
4+
//
5+
// Created by Thomas Thorpe on 25/02/2013.
6+
// Copyright (c) 2013 Thomas Thorpe. All rights reserved.
7+
//
8+
9+
#import "TabThreeViewController.h"
10+
11+
/**
12+
This example uses the cellZoomXOffset and cellZoomYOffset properties to get the cell to appear
13+
diagonally from the bottom left, as well as the cellZoomAnimationDuration property to increase the speed.
14+
*/
15+
@implementation TabThreeViewController
16+
17+
-(void)viewDidLoad{
18+
[self.tableView registerNib:[UINib nibWithNibName:@"FancyCellView" bundle:nil]
19+
forCellReuseIdentifier:@"FancyCellView"];
20+
21+
self.cellZoomXOffset = [NSNumber numberWithFloat:-75];
22+
self.cellZoomYOffset = [NSNumber numberWithFloat:75];
23+
self.cellZoomAnimationDuration = [NSNumber numberWithFloat:0.3];
24+
}
25+
26+
#pragma mark - Table view data source
27+
28+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
29+
{
30+
// Return the number of sections.
31+
return 1;
32+
}
33+
34+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
35+
{
36+
37+
// Return the number of rows in the section.
38+
return 50;
39+
}
40+
41+
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
42+
{
43+
return 204;
44+
}
45+
46+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
47+
{
48+
static NSString *CellIdentifier = @"FancyCellView";
49+
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
50+
51+
// Configure the cell...
52+
53+
return cell;
54+
}
55+
56+
57+
58+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
3+
<data>
4+
<int key="IBDocument.SystemTarget">1552</int>
5+
<string key="IBDocument.SystemVersion">12C60</string>
6+
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
7+
<string key="IBDocument.AppKitVersion">1187.34</string>
8+
<string key="IBDocument.HIToolboxVersion">625.00</string>
9+
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
10+
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
11+
<string key="NS.object.0">2083</string>
12+
</object>
13+
<array key="IBDocument.IntegratedClassDependencies">
14+
<string>IBProxyObject</string>
15+
<string>IBUITableView</string>
16+
</array>
17+
<array key="IBDocument.PluginDependencies">
18+
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
19+
</array>
20+
<object class="NSMutableDictionary" key="IBDocument.Metadata">
21+
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
22+
<integer value="1" key="NS.object.0"/>
23+
</object>
24+
<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
25+
<object class="IBProxyObject" id="372490531">
26+
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
27+
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
28+
</object>
29+
<object class="IBProxyObject" id="975951072">
30+
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
31+
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
32+
</object>
33+
<object class="IBUITableView" id="873029372">
34+
<reference key="NSNextResponder"/>
35+
<int key="NSvFlags">274</int>
36+
<string key="NSFrame">{{0, 20}, {320, 548}}</string>
37+
<reference key="NSSuperview"/>
38+
<reference key="NSNextKeyView"/>
39+
<object class="NSColor" key="IBUIBackgroundColor">
40+
<int key="NSColorSpace">3</int>
41+
<bytes key="NSWhite">MC4xNzQ0Njk2NjI0AA</bytes>
42+
</object>
43+
<bool key="IBUIOpaque">NO</bool>
44+
<bool key="IBUIClipsSubviews">YES</bool>
45+
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
46+
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
47+
<object class="IBUIScreenMetrics" key="IBUISimulatedDestinationMetrics">
48+
<string key="IBUISimulatedSizeMetricsClass">IBUIScreenMetrics</string>
49+
<object class="NSMutableDictionary" key="IBUINormalizedOrientationToSizeMap">
50+
<bool key="EncodedWithXMLCoder">YES</bool>
51+
<array key="dict.sortedKeys">
52+
<integer value="1"/>
53+
<integer value="3"/>
54+
</array>
55+
<array key="dict.values">
56+
<string>{320, 568}</string>
57+
<string>{568, 320}</string>
58+
</array>
59+
</object>
60+
<string key="IBUITargetRuntime">IBCocoaTouchFramework</string>
61+
<string key="IBUIDisplayName">Retina 4 Full Screen</string>
62+
<int key="IBUIType">2</int>
63+
</object>
64+
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
65+
<bool key="IBUIBouncesZoom">NO</bool>
66+
<int key="IBUISectionIndexMinimumDisplayRowCount">0</int>
67+
<bool key="IBUIShowsSelectionImmediatelyOnTouchBegin">YES</bool>
68+
<float key="IBUIRowHeight">44</float>
69+
<float key="IBUISectionHeaderHeight">22</float>
70+
<float key="IBUISectionFooterHeight">22</float>
71+
</object>
72+
</array>
73+
<object class="IBObjectContainer" key="IBDocument.Objects">
74+
<array class="NSMutableArray" key="connectionRecords">
75+
<object class="IBConnectionRecord">
76+
<object class="IBCocoaTouchOutletConnection" key="connection">
77+
<string key="label">view</string>
78+
<reference key="source" ref="372490531"/>
79+
<reference key="destination" ref="873029372"/>
80+
</object>
81+
<int key="connectionID">5</int>
82+
</object>
83+
<object class="IBConnectionRecord">
84+
<object class="IBCocoaTouchOutletConnection" key="connection">
85+
<string key="label">dataSource</string>
86+
<reference key="source" ref="873029372"/>
87+
<reference key="destination" ref="372490531"/>
88+
</object>
89+
<int key="connectionID">6</int>
90+
</object>
91+
<object class="IBConnectionRecord">
92+
<object class="IBCocoaTouchOutletConnection" key="connection">
93+
<string key="label">delegate</string>
94+
<reference key="source" ref="873029372"/>
95+
<reference key="destination" ref="372490531"/>
96+
</object>
97+
<int key="connectionID">7</int>
98+
</object>
99+
</array>
100+
<object class="IBMutableOrderedSet" key="objectRecords">
101+
<array key="orderedObjects">
102+
<object class="IBObjectRecord">
103+
<int key="objectID">0</int>
104+
<array key="object" id="0"/>
105+
<reference key="children" ref="1000"/>
106+
<nil key="parent"/>
107+
</object>
108+
<object class="IBObjectRecord">
109+
<int key="objectID">-1</int>
110+
<reference key="object" ref="372490531"/>
111+
<reference key="parent" ref="0"/>
112+
<string key="objectName">File's Owner</string>
113+
</object>
114+
<object class="IBObjectRecord">
115+
<int key="objectID">-2</int>
116+
<reference key="object" ref="975951072"/>
117+
<reference key="parent" ref="0"/>
118+
</object>
119+
<object class="IBObjectRecord">
120+
<int key="objectID">4</int>
121+
<reference key="object" ref="873029372"/>
122+
<reference key="parent" ref="0"/>
123+
</object>
124+
</array>
125+
</object>
126+
<dictionary class="NSMutableDictionary" key="flattenedProperties">
127+
<string key="-1.CustomClassName">TabThreeViewController</string>
128+
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
129+
<string key="-2.CustomClassName">UIResponder</string>
130+
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
131+
<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
132+
</dictionary>
133+
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
134+
<nil key="activeLocalization"/>
135+
<dictionary class="NSMutableDictionary" key="localizations"/>
136+
<nil key="sourceID"/>
137+
<int key="maxID">7</int>
138+
</object>
139+
<object class="IBClassDescriber" key="IBDocument.Classes"/>
140+
<int key="IBDocument.localizationMode">0</int>
141+
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
142+
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
143+
<int key="IBDocument.defaultPropertyAccessControl">3</int>
144+
<string key="IBCocoaTouchPluginVersion">2083</string>
145+
</data>
146+
</archive>

Diff for: UITableViewZoomController/Demo/TableViews/TabTwoViewController.m

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
@implementation TabTwoViewController
1212

13+
/**
14+
This example changes the initial alpha to be 1.0 so that the cell does not fade in. It also changes the animation duration to 0.5 seconds rather than the default, and changes the scale of both axes to be 0.9 so they are stretched less than the default, and zoom in (because the number is less than 1) rather than zooming out like the default does. It uses standard table view cells with text in rather than custom cells.
15+
*/
1316
-(void)viewDidLoad{
1417
self.cellZoomInitialAlpha = [NSNumber numberWithFloat:1.0];
1518
self.cellZoomAnimationDuration = [NSNumber numberWithFloat:0.5];

Diff for: UITableViewZoomController/Source/TTUITableViewZoomController.h

+14-4
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,32 @@
2929

3030
/** @property cellZoomXScaleFactor
3131
* @brief The X Zoom Factor
32-
* How much to scale to x axis of the cell before it is animated back to normal size. 1 is normal size. >1 is bigger, <1 is smaller. **/
32+
* How much to scale to x axis of the cell before it is animated back to normal size. 1 is normal size. >1 is bigger, <1 is smaller. Default if not set is 1.25 **/
3333
@property (strong, nonatomic) NSNumber* cellZoomXScaleFactor;
3434

3535
/** @property cellZoomYScaleFactor
3636
* @brief The Y Zoom Factor
37-
* How much to scale to y axis of the cell before it is animated back to normal size. 1 is normal size. >1 is bigger, <1 is smaller. **/
37+
* How much to scale to y axis of the cell before it is animated back to normal size. 1 is normal size. >1 is bigger, <1 is smaller. Default if not set is 1.25 **/
3838
@property (strong, nonatomic) NSNumber* cellZoomYScaleFactor;
3939

40+
/** @property cellZoomXOffset
41+
* @brief Specify an X offset (in pixels) for the animation's initial position
42+
* Allows you to specify an X offset (in pixels) for the animation's initial position, so for example if you say -50 this will mean as well as the rest of the animation, the cell also comes in from 50 pixels to the left of the screen. If you say 100 it will come in from 100 pixels to the right of the screen. Combine it with the cellZoomYOffset to get the cell to come in diagonally (see TabThreeViewController in Demo examples). If not set, the default is 0. **/
43+
@property (strong, nonatomic) NSNumber* cellZoomXOffset;
44+
45+
/** @property cellZoomYOffset
46+
* @brief Specify a Y offset (in pixels). for the animations initial position
47+
* Allows you to specify a Y offset (in pixels) for the animation's initial position, so for example if you say -50 this will mean as well as the rest of the animation, the cell also comes in from 50 pixels to the top of the screen. If you say 100 it will come in from 100 pixels to the bottom of the screen. Combine it with the cellZoomXOffset to get the cell to come in diagonally (see TabThreeViewController in Demo examples). If not set, the default is 0. **/
48+
@property (strong, nonatomic) NSNumber* cellZoomYOffset;
49+
4050
/** @property cellZoomInitialAlpha
4151
* @brief The inital Alpha value of the cell
42-
* The initial alpha value of the cell when it starts animation. For example if you set this to be 0 then the cell will begin completely transparent, and will fade into view as well as zooming. Value between 0 and 1. **/
52+
* The initial alpha value of the cell when it starts animation. For example if you set this to be 0 then the cell will begin completely transparent, and will fade into view as well as zooming. Value between 0 and 1. Default if not set is 0.3 **/
4353
@property (strong, nonatomic) NSNumber* cellZoomInitialAlpha;
4454

4555
/** @property cellZoomAnimationDuration
4656
* @brief The Animation Duration
47-
* The duration of the animation effect, in seconds. **/
57+
* The duration of the animation effect, in seconds. Default if not set is 0.65 seconds **/
4858
@property (strong, nonatomic) NSNumber* cellZoomAnimationDuration;
4959

5060
/*

Diff for: UITableViewZoomController/Source/TTUITableViewZoomController.m

+17-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce
4040

4141
//now make the image view a bit bigger, so we can do a zoomout effect when it becomes visible
4242
cell.contentView.alpha = self.cellZoomInitialAlpha.floatValue;
43-
cell.contentView.transform = CGAffineTransformMakeScale(self.cellZoomXScaleFactor.floatValue, self.cellZoomYScaleFactor.floatValue);
43+
44+
CGAffineTransform transformScale = CGAffineTransformMakeScale(self.cellZoomXScaleFactor.floatValue, self.cellZoomYScaleFactor.floatValue);
45+
CGAffineTransform transformTranslate = CGAffineTransformMakeTranslation(self.cellZoomXOffset.floatValue, self.cellZoomYOffset.floatValue);
46+
47+
cell.contentView.transform = CGAffineTransformConcat(transformScale, transformTranslate);
4448

4549
[self.tableView bringSubviewToFront:cell.contentView];
4650
[UIView animateWithDuration:self.cellZoomAnimationDuration.floatValue animations:^{
@@ -81,6 +85,18 @@ -(NSNumber *)cellZoomXScaleFactor{
8185
}
8286
return _xZoomFactor;
8387
}
88+
-(NSNumber *)cellZoomXOffset{
89+
if (_cellZoomXOffset == nil){
90+
_cellZoomXOffset = [NSNumber numberWithFloat:0];
91+
}
92+
return _cellZoomXOffset;
93+
}
94+
-(NSNumber *)cellZoomYOffset{
95+
if (_cellZoomYOffset == nil){
96+
_cellZoomYOffset = [NSNumber numberWithFloat:0];
97+
}
98+
return _cellZoomYOffset;
99+
}
84100
-(NSNumber *)cellZoomYScaleFactor{
85101
if (_yZoomFactor == nil){
86102
_yZoomFactor = [NSNumber numberWithFloat:1.25];

0 commit comments

Comments
 (0)