Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slider value reset gesture #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions Transformifier/Transformifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ a copy of this software and associated documentation files (the
transformTypePerspective= 5
} enumTransformType;

#define kSliderDefaultValue_Scale 100.0
#define kSliderDefaultValue_Other 0.0

@interface Transformifier()

@property (nonatomic, strong) CALayer *layer;
Expand Down Expand Up @@ -92,11 +95,11 @@ - (void)loadView {

- (void)reload {
NSNumber *zeroInt = [NSNumber numberWithInt:0];
NSMutableDictionary *rotate = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypeRotate], @"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat: 0.0] }];
NSMutableDictionary *translate = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypeTranslate], @"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat: 0.0] }];
NSMutableDictionary *scale = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypeScale], @"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat:100.0] }];
NSMutableDictionary *skew = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypeSkew], @"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat: 0.0] }];
NSMutableDictionary *perspective = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypePerspective],@"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat: 0.0] }];
NSMutableDictionary *rotate = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypeRotate], @"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat: kSliderDefaultValue_Other] }];
NSMutableDictionary *translate = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypeTranslate], @"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat: kSliderDefaultValue_Other] }];
NSMutableDictionary *scale = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypeScale], @"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat:kSliderDefaultValue_Scale] }];
NSMutableDictionary *skew = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypeSkew], @"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat: kSliderDefaultValue_Other] }];
NSMutableDictionary *perspective = [NSMutableDictionary dictionaryWithDictionary:@{@"type" : [NSNumber numberWithInt:transformTypePerspective],@"axisIndex" : zeroInt, @"value" : [NSNumber numberWithFloat: kSliderDefaultValue_Other] }];

self.transformsArray = [NSMutableArray arrayWithArray:@[ rotate, translate, scale ]];
self.sourceArray = [NSMutableArray arrayWithArray:@[ skew, perspective, rotate, translate, scale ]];
Expand Down Expand Up @@ -319,6 +322,10 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
self.slider = [[UISlider alloc] initWithFrame:CGRectMake(10, 35, 200, 20)];
[self.contentView addSubview:slider];

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resetSlider:)];
doubleTap.numberOfTapsRequired = 2;
[slider addGestureRecognizer:doubleTap];

[axisChooser addTarget:self action:@selector(setAxisIndex) forControlEvents:UIControlEventValueChanged];
[slider addTarget:self action:@selector(setValueLabel) forControlEvents:UIControlEventValueChanged];
}
Expand Down Expand Up @@ -380,7 +387,7 @@ - (void)setEnabled:(BOOL)value {
}

- (void)setAxisIndex {
[transformData setValue:[NSNumber numberWithInt:axisChooser.selectedSegmentIndex] forKey:@"axisIndex"];
[transformData setValue:[NSNumber numberWithInt:(int)axisChooser.selectedSegmentIndex] forKey:@"axisIndex"];
[delegate applyTransform];
}

Expand All @@ -400,6 +407,17 @@ - (void)setValueLabel {
[delegate applyTransform];
}

- (void)resetSlider:(UITapGestureRecognizer *)sender
{
if (transformType == transformTypeScale) {
slider.value = kSliderDefaultValue_Scale;
} else {
slider.value = kSliderDefaultValue_Other;
}

[self setValueLabel];
}


@end