Skip to content
Open
Show file tree
Hide file tree
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
Binary file added CRRulerControl/.DS_Store
Binary file not shown.
20 changes: 13 additions & 7 deletions CRRulerControl/Classes/CRRulerControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ @interface CRRulerControl () <UIScrollViewDelegate>
@property (nonatomic) CRRulerLayer *rulerLayer;
@property (nonatomic, readwrite) UIScrollView *scrollView;
@property (nonatomic, readwrite) UIImageView *pointerImageView;

@property (nonatomic, assign) BOOL isSetValued;
@end

@implementation CRRulerControl
Expand Down Expand Up @@ -129,7 +129,12 @@ - (void)setupRulerLayer {

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat oldValue = _value;
_value = [self valueForContentOffset:scrollView.contentOffset];
if (_isSetValued) {
_value = [self valueForContentOffset:[self contentOffsetForValue:_value]];
_isSetValued = false;
}else{
_value = [self valueForContentOffset:scrollView.contentOffset];
}
if (oldValue != _value) {
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
Expand Down Expand Up @@ -159,16 +164,16 @@ - (CGFloat)valueForContentOffset:(CGPoint)contentOffset {
}

- (CGFloat)offsetCoefficient {
NSInteger distance = self.rulerRange.length;
CGFloat distance = self.rulerRange.length;
return (self.scrollView.contentSize.width - kSideOffset * 2) / distance;
}

#pragma mark - User interaction

- (void)tintColorDidChange {
[self setColor:self.tintColor forMarkType:CRRulerMarkTypeAll];
[self setTextColor:self.tintColor forMarkType:CRRulerMarkTypeMiddle | CRRulerMarkTypeMajor];
self.pointerImageView.backgroundColor = self.tintColor;
// [self setColor:self.tintColor forMarkType:CRRulerMarkTypeAll];
// [self setTextColor:self.tintColor forMarkType:CRRulerMarkTypeMiddle | CRRulerMarkTypeMajor];
// self.pointerImageView.backgroundColor = self.tintColor;
}

#pragma mark - Setters
Expand Down Expand Up @@ -216,6 +221,7 @@ - (void)setValue:(CGFloat)value {

- (void)setValue:(CGFloat)value animated:(BOOL)animated {
_value = value;
_isSetValued = true;
[self.scrollView setContentOffset:[self contentOffsetForValue:value] animated:animated];
}

Expand Down Expand Up @@ -469,4 +475,4 @@ - (CGPoint)offsetForMarkType:(CRRulerMarkType)markType {
return CGPointZero;
}

@end
@end