diff --git a/ElasticTransistionExample/Cell/CellDimensionAndTypeDelegate.h b/ElasticTransistionExample/Cell/CellDimensionAndTypeDelegate.h index 700bb2f..2d6f2b5 100644 --- a/ElasticTransistionExample/Cell/CellDimensionAndTypeDelegate.h +++ b/ElasticTransistionExample/Cell/CellDimensionAndTypeDelegate.h @@ -11,6 +11,7 @@ typedef NS_ENUM(int, PropertyRelated){ STICKY, SHADOW, + TRANSFORM, RADIUS }; diff --git a/ElasticTransistionExample/Cell/CellModel/SegmentCellModel.h b/ElasticTransistionExample/Cell/CellModel/SegmentCellModel.h new file mode 100644 index 0000000..8a8b818 --- /dev/null +++ b/ElasticTransistionExample/Cell/CellModel/SegmentCellModel.h @@ -0,0 +1,31 @@ +// +// SegmentCellModel.h +// ElasticTransitionExample +// +// Created by Tigielle on 16/02/16. +// Copyright © 2016 Matteo Tagliafico. All rights reserved. +// + +#import +#import "CellDimensionAndTypeDelegate.h" + +@protocol CellSegmentChange; + +@interface SegmentCellModel : NSObject + +@property (nonatomic) NSArray *values; +@property (nonatomic) NSInteger index; +@property (nonatomic, weak) id delegate; + +- (void)setSelcetedTransformIndex:(NSInteger)index; + +@end + + +@protocol CellSegmentChange + +@optional + +-(void)didSelcetedTransformIndex:(NSInteger)index AndPropertyRelated:(PropertyRelated)property; + +@end \ No newline at end of file diff --git a/ElasticTransistionExample/Cell/CellModel/SegmentCellModel.m b/ElasticTransistionExample/Cell/CellModel/SegmentCellModel.m new file mode 100644 index 0000000..f9070d8 --- /dev/null +++ b/ElasticTransistionExample/Cell/CellModel/SegmentCellModel.m @@ -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 strongDelegate = self.delegate; + + if([strongDelegate respondsToSelector:@selector(didSelcetedTransformIndex:AndPropertyRelated:)]){ + + [strongDelegate didSelcetedTransformIndex:index AndPropertyRelated:TRANSFORM]; + } +} + +@end diff --git a/ElasticTransistionExample/Cell/CellModel/SwitchCellModel.m b/ElasticTransistionExample/Cell/CellModel/SwitchCellModel.m index 5f26f3c..0d2f67f 100644 --- a/ElasticTransistionExample/Cell/CellModel/SwitchCellModel.m +++ b/ElasticTransistionExample/Cell/CellModel/SwitchCellModel.m @@ -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{ diff --git a/ElasticTransistionExample/Cell/SegmentCell.h b/ElasticTransistionExample/Cell/SegmentCell.h index 8d601b8..5d3220c 100644 --- a/ElasticTransistionExample/Cell/SegmentCell.h +++ b/ElasticTransistionExample/Cell/SegmentCell.h @@ -7,15 +7,16 @@ // #import -#import "CellDimensionAndTypeDelegate.h" +#import "SegmentCellModel.h" -@interface SegmentCell : UITableViewCell +@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 \ No newline at end of file diff --git a/ElasticTransistionExample/Cell/SegmentCell.m b/ElasticTransistionExample/Cell/SegmentCell.m index 1af6b59..73d048d 100644 --- a/ElasticTransistionExample/Cell/SegmentCell.m +++ b/ElasticTransistionExample/Cell/SegmentCell.m @@ -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 diff --git a/ElasticTransistionExample/OptionsViewController.m b/ElasticTransistionExample/OptionsViewController.m index 5dad38f..099b9ea 100644 --- a/ElasticTransistionExample/OptionsViewController.m +++ b/ElasticTransistionExample/OptionsViewController.m @@ -9,12 +9,16 @@ #import "OptionsViewController.h" #import "SwitchCellModel.h" +#import "SegmentCellModel.h" #import "SwitchCell.h" #import "SliderCell.h" #import "SegmentCell.h" -@interface OptionsViewController (){ +#define kHeightSwitchCell 54 +#define kHeightSegmentCell 72 + +@interface OptionsViewController (){ ElasticTransition *tm; NSMutableArray *menuItems; @@ -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++) { @@ -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; @@ -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; - } @@ -129,13 +160,12 @@ -(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 *item = (NSObject *) itemModel; + NSObject *itemProt = (NSObject *) itemModel; - return item.rowHeigth; + return itemProt.rowHeigth; }else{ return 0.0; @@ -143,6 +173,8 @@ -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPat } +#pragma mark - Listen to table changes + -(void)didChangeStateToOn:(BOOL)on AndPropertyRelated:(PropertyRelated)property{ switch (property) { @@ -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; } diff --git a/ElasticTransitionExample.xcodeproj/project.pbxproj b/ElasticTransitionExample.xcodeproj/project.pbxproj index d010b89..85b6ada 100644 --- a/ElasticTransitionExample.xcodeproj/project.pbxproj +++ b/ElasticTransitionExample.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 = ""; }; + BABE5AB71C73DA69004AF533 /* SegmentCellModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SegmentCellModel.m; path = Cell/CellModel/SegmentCellModel.m; sourceTree = ""; }; 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 = ""; }; BAC47DF91C6C09D200F8E005 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -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; @@ -184,6 +187,8 @@ children = ( BAFB89711C73352500FDA257 /* SwitchCellModel.h */, BAFB89721C73352500FDA257 /* SwitchCellModel.m */, + BABE5AB61C73DA69004AF533 /* SegmentCellModel.h */, + BABE5AB71C73DA69004AF533 /* SegmentCellModel.m */, ); name = "Cell Model"; sourceTree = ""; @@ -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 */, diff --git a/ElasticTransitionExample.xcodeproj/project.xcworkspace/xcuserdata/tigielle.xcuserdatad/UserInterfaceState.xcuserstate b/ElasticTransitionExample.xcodeproj/project.xcworkspace/xcuserdata/tigielle.xcuserdatad/UserInterfaceState.xcuserstate index 19f7466..da7daab 100644 Binary files a/ElasticTransitionExample.xcodeproj/project.xcworkspace/xcuserdata/tigielle.xcuserdatad/UserInterfaceState.xcuserstate and b/ElasticTransitionExample.xcodeproj/project.xcworkspace/xcuserdata/tigielle.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ElasticTransitionExample.xcodeproj/xcuserdata/tigielle.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ElasticTransitionExample.xcodeproj/xcuserdata/tigielle.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index fbff2e2..19a04a7 100644 --- a/ElasticTransitionExample.xcodeproj/xcuserdata/tigielle.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ElasticTransitionExample.xcodeproj/xcuserdata/tigielle.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -9,13 +9,13 @@ shouldBeEnabled = "Yes" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "ElasticTransition/EdgePanTransition.m" - timestampString = "477306304.002398" + filePath = "ElasticTransistionExample/Cell/SegmentCell.m" + timestampString = "477355918.714085" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "318" - endingLineNumber = "318" - landmarkName = "-navigationController:animationControllerForOperation:fromViewController:toViewController:" + startingLineNumber = "19" + endingLineNumber = "19" + landmarkName = "-setCellModel:" landmarkType = "5"> @@ -25,253 +25,13 @@ shouldBeEnabled = "Yes" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "ElasticTransition/EdgePanTransition.m" - timestampString = "477306305.178351" + filePath = "ElasticTransistionExample/Cell/CellModel/SegmentCellModel.m" + timestampString = "477356423.448745" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "312" - endingLineNumber = "312" - landmarkName = "-navigationController:interactionControllerForAnimationController:" - landmarkType = "5"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -