Skip to content

Commit

Permalink
Added the ability to change 'transformType' from option.
Browse files Browse the repository at this point in the history
  • Loading branch information
taglia committed Feb 16, 2016
1 parent 83e334a commit 2eaa186
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
typedef NS_ENUM(int, PropertyRelated){
STICKY,
SHADOW,
TRANSFORM,
RADIUS
};

Expand Down
31 changes: 31 additions & 0 deletions ElasticTransistionExample/Cell/CellModel/SegmentCellModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// SegmentCellModel.h
// ElasticTransitionExample
//
// Created by Tigielle on 16/02/16.
// Copyright © 2016 Matteo Tagliafico. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CellDimensionAndTypeDelegate.h"

@protocol CellSegmentChange;

@interface SegmentCellModel : NSObject <CellDimensionAndTypeDelegate>

@property (nonatomic) NSArray *values;
@property (nonatomic) NSInteger index;
@property (nonatomic, weak) id<CellSegmentChange> delegate;

- (void)setSelcetedTransformIndex:(NSInteger)index;

@end


@protocol CellSegmentChange <NSObject>

@optional

-(void)didSelcetedTransformIndex:(NSInteger)index AndPropertyRelated:(PropertyRelated)property;

@end
29 changes: 29 additions & 0 deletions ElasticTransistionExample/Cell/CellModel/SegmentCellModel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// SegmentCellModel.m
// ElasticTransitionExample
//
// Created by Tigielle on 16/02/16.
// Copyright © 2016 Matteo Tagliafico. All rights reserved.
//

#import "SegmentCellModel.h"

@implementation SegmentCellModel

@synthesize type, rowHeigth;
@synthesize name;


- (void)setSelcetedTransformIndex:(NSInteger)index{

self.index = index;

id<CellSegmentChange> strongDelegate = self.delegate;

if([strongDelegate respondsToSelector:@selector(didSelcetedTransformIndex:AndPropertyRelated:)]){

[strongDelegate didSelcetedTransformIndex:index AndPropertyRelated:TRANSFORM];
}
}

@end
13 changes: 0 additions & 13 deletions ElasticTransistionExample/Cell/CellModel/SwitchCellModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@ @implementation SwitchCellModel
@synthesize type, rowHeigth;
@synthesize name;

-(id)initWithName:(NSString*)aName AndOn:(BOOL)on{

self = [super init];

if(self){

self.rowHeigth = 54.0;
self.name = aName;
self.on = on;
}

return self;
}

- (void)setSwitchOn:(BOOL)on{

Expand Down
11 changes: 6 additions & 5 deletions ElasticTransistionExample/Cell/SegmentCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
//

#import <UIKit/UIKit.h>
#import "CellDimensionAndTypeDelegate.h"
#import "SegmentCellModel.h"

@interface SegmentCell : UITableViewCell <CellDimensionAndTypeDelegate>
@interface SegmentCell : UITableViewCell

@property (nonatomic) NSMutableArray *values;

@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
@property (nonatomic, weak) IBOutlet UISegmentedControl *segment;
@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
@property (nonatomic) IBOutlet UISegmentedControl *segment;
@property (nonatomic, weak) SegmentCellModel *cellModel;

-(IBAction)segmentChanged:(UISegmentedControl*)sender;

@end
@end
32 changes: 20 additions & 12 deletions ElasticTransistionExample/Cell/SegmentCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,35 @@

@implementation SegmentCell

@synthesize type, rowHeigth;
@synthesize cellModel, segment;

- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
- (void)setCellModel:(SegmentCellModel *)aCellModel{

if (self) {

self.rowHeigth = 72.0;
}
self->cellModel = aCellModel;

[self setSegments: aCellModel.values];

return self;
self.nameLabel.text = aCellModel.name;
}

-(void)onChangeValue:(id)value{

-(IBAction)segmentChanged:(UISegmentedControl*)sender{

[self.cellModel setSelcetedTransformIndex:sender.selectedSegmentIndex];
}

-(IBAction)segmentChanged:(UISegmentedControl*)sender{
- (void)setSegments:(NSArray *)segments
{
[self.segment removeAllSegments];

int i = 0;

for (NSString *str in segments) {
[self.segment insertSegmentWithTitle:str atIndex:i animated:NO];
i++;
}

[self onChangeValue:self.values[sender.selectedSegmentIndex]];
[self.segment setSelectedSegmentIndex:self.cellModel.index];
}

@end
80 changes: 66 additions & 14 deletions ElasticTransistionExample/OptionsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
#import "OptionsViewController.h"

#import "SwitchCellModel.h"
#import "SegmentCellModel.h"

#import "SwitchCell.h"
#import "SliderCell.h"
#import "SegmentCell.h"

@interface OptionsViewController ()<CellStateChange>{
#define kHeightSwitchCell 54
#define kHeightSegmentCell 72

@interface OptionsViewController ()<CellStateChange, CellSegmentChange>{

ElasticTransition *tm;
NSMutableArray *menuItems;
Expand Down Expand Up @@ -51,29 +55,55 @@ - (void)viewDidLoad {


NSMutableArray *va = [[NSMutableArray alloc] init];
[va addObject:[NSNumber numberWithInt:NONE]];
[va addObject:[NSNumber numberWithInt:ROTATE]];
[va addObject:[NSNumber numberWithInt:TRANSLATEMID]];
[va addObject:@"NONE"];
[va addObject:@"ROTATE"];
[va addObject:@"TRANSLATE MID"];


menuItems = [[NSMutableArray alloc] init];

SwitchCellModel *stickySwitchModel = [[SwitchCellModel alloc]init];
stickySwitchModel.name = @"Sticky";
stickySwitchModel.on = tm.sticky;
stickySwitchModel.rowHeigth = 54.0;
stickySwitchModel.type = STICKY;
stickySwitchModel.on = tm.sticky;
stickySwitchModel.rowHeigth = kHeightSwitchCell;
stickySwitchModel.delegate = self;
[menuItems addObject:stickySwitchModel];

SwitchCellModel *shadowSwitchModel = [[SwitchCellModel alloc]init];
shadowSwitchModel.name = @"Shadow";
shadowSwitchModel.on = tm.showShadow;
shadowSwitchModel.rowHeigth = 54.0;
shadowSwitchModel.type = SHADOW;
shadowSwitchModel.on = tm.showShadow;
shadowSwitchModel.rowHeigth = kHeightSwitchCell;
shadowSwitchModel.delegate = self;
[menuItems addObject:shadowSwitchModel];

SegmentCellModel *transformSegmentModel = [[SegmentCellModel alloc]init];
transformSegmentModel.name = @"Transform Type";
transformSegmentModel.type = TRANSFORM;
transformSegmentModel. values = [va copy];

switch (tm.transformType) {
case NONE:
transformSegmentModel.index = 0;
break;
case ROTATE:
transformSegmentModel.index = 1;
break;
case TRANSLATEMID:
case TRANSLATEPULL:
case TRANSLATEPUSH:
transformSegmentModel.index = 2;
break;

default:
break;
}

transformSegmentModel.rowHeigth = kHeightSegmentCell;
transformSegmentModel.delegate = self;
[menuItems addObject:transformSegmentModel];


for (int i = 0 ; i < menuItems.count; i++) {

Expand All @@ -100,7 +130,6 @@ -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSI
case 1:
{
SwitchCellModel *itemModel = (SwitchCellModel *) [menuItems objectAtIndex:indexPath.row];


SwitchCell *switchCell = [tableView dequeueReusableCellWithIdentifier:@"switch" forIndexPath:indexPath];
switchCell.cellModel = itemModel;
Expand All @@ -110,15 +139,17 @@ -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSI
}
case 2:
{
SegmentCellModel *itemModel = (SegmentCellModel *) [menuItems objectAtIndex:indexPath.row];

SegmentCell *segmentCell = [tableView dequeueReusableCellWithIdentifier:@"segment" forIndexPath:indexPath];
segmentCell.cellModel = itemModel;
cell = segmentCell;
}
default:
break;
}


return cell;

}


Expand All @@ -129,20 +160,21 @@ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{


NSObject *itemModel = [menuItems objectAtIndex:indexPath.row];

if ([[itemModel class] conformsToProtocol:@protocol(CellDimensionAndTypeDelegate)]) {
NSObject <CellDimensionAndTypeDelegate> *item = (NSObject <CellDimensionAndTypeDelegate> *) itemModel;
NSObject <CellDimensionAndTypeDelegate> *itemProt = (NSObject <CellDimensionAndTypeDelegate> *) itemModel;

return item.rowHeigth;
return itemProt.rowHeigth;

}else{
return 0.0;
}
}


#pragma mark - Listen to table changes

-(void)didChangeStateToOn:(BOOL)on AndPropertyRelated:(PropertyRelated)property{

switch (property) {
Expand All @@ -157,6 +189,26 @@ -(void)didChangeStateToOn:(BOOL)on AndPropertyRelated:(PropertyRelated)property{
}
}

-(void)didSelcetedTransformIndex:(NSInteger)index AndPropertyRelated:(PropertyRelated)property{

if (property == TRANSFORM) {

switch (index) {
case 0:
tm.transformType = NONE;
break;
case 1:
tm.transformType = ROTATE;
break;
case 2:
tm.transformType = TRANSLATEMID;
break;
default:
break;
}
}
}

-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
Expand Down
10 changes: 8 additions & 2 deletions ElasticTransitionExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
BA70DEB91C6F7F10008B5DB4 /* HelperFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = BA70DEB81C6F7F10008B5DB4 /* HelperFunctions.m */; };
BABE5AB81C73DA69004AF533 /* SegmentCellModel.m in Sources */ = {isa = PBXBuildFile; fileRef = BABE5AB71C73DA69004AF533 /* SegmentCellModel.m */; };
BAC47DF81C6C09D200F8E005 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC47DF71C6C09D200F8E005 /* main.m */; };
BAC47DFB1C6C09D200F8E005 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC47DFA1C6C09D200F8E005 /* AppDelegate.m */; };
BAC47E011C6C09D200F8E005 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BAC47DFF1C6C09D200F8E005 /* Main.storyboard */; };
Expand All @@ -32,6 +33,8 @@
/* Begin PBXFileReference section */
BA70DEB71C6F7F10008B5DB4 /* HelperFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HelperFunctions.h; path = ElasticTransition/Utils/HelperFunctions.h; sourceTree = SOURCE_ROOT; };
BA70DEB81C6F7F10008B5DB4 /* HelperFunctions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HelperFunctions.m; path = ElasticTransition/Utils/HelperFunctions.m; sourceTree = SOURCE_ROOT; };
BABE5AB61C73DA69004AF533 /* SegmentCellModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SegmentCellModel.h; path = Cell/CellModel/SegmentCellModel.h; sourceTree = "<group>"; };
BABE5AB71C73DA69004AF533 /* SegmentCellModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SegmentCellModel.m; path = Cell/CellModel/SegmentCellModel.m; sourceTree = "<group>"; };
BAC47DF31C6C09D200F8E005 /* ElasticTransitionExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ElasticTransitionExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
BAC47DF71C6C09D200F8E005 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
BAC47DF91C6C09D200F8E005 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -170,10 +173,10 @@
BAFB89701C7334F700FDA257 /* Cell Model */,
BAFB89661C732F5400FDA257 /* SwitchCell.h */,
BAFB89671C732F5400FDA257 /* SwitchCell.m */,
BAFB89691C732F6900FDA257 /* SliderCell.h */,
BAFB896A1C732F6900FDA257 /* SliderCell.m */,
BAFB896C1C732F7C00FDA257 /* SegmentCell.h */,
BAFB896D1C732F7C00FDA257 /* SegmentCell.m */,
BAFB89691C732F6900FDA257 /* SliderCell.h */,
BAFB896A1C732F6900FDA257 /* SliderCell.m */,
BAFB896F1C732FC900FDA257 /* CellDimensionAndTypeDelegate.h */,
);
name = Cell;
Expand All @@ -184,6 +187,8 @@
children = (
BAFB89711C73352500FDA257 /* SwitchCellModel.h */,
BAFB89721C73352500FDA257 /* SwitchCellModel.m */,
BABE5AB61C73DA69004AF533 /* SegmentCellModel.h */,
BABE5AB71C73DA69004AF533 /* SegmentCellModel.m */,
);
name = "Cell Model";
sourceTree = "<group>";
Expand Down Expand Up @@ -265,6 +270,7 @@
BAFB896B1C732F6900FDA257 /* SliderCell.m in Sources */,
BAC47E351C6C97CD00F8E005 /* MenuViewController.m in Sources */,
BAC47E381C6C97F900F8E005 /* NavigationExampleViewController.m in Sources */,
BABE5AB81C73DA69004AF533 /* SegmentCellModel.m in Sources */,
BAFB89731C73352500FDA257 /* SwitchCellModel.m in Sources */,
BAC47E441C6C999900F8E005 /* ElasticTransition.m in Sources */,
BA70DEB91C6F7F10008B5DB4 /* HelperFunctions.m in Sources */,
Expand Down
Binary file not shown.
Loading

0 comments on commit 2eaa186

Please sign in to comment.