diff --git a/CRRulerControl/.DS_Store b/CRRulerControl/.DS_Store new file mode 100644 index 0000000..0306d46 Binary files /dev/null and b/CRRulerControl/.DS_Store differ diff --git a/CRRulerControl/Classes/CRRulerControl.m b/CRRulerControl/Classes/CRRulerControl.m index 01eb7a4..7376ff9 100644 --- a/CRRulerControl/Classes/CRRulerControl.m +++ b/CRRulerControl/Classes/CRRulerControl.m @@ -21,7 +21,7 @@ @interface CRRulerControl () @property (nonatomic) CRRulerLayer *rulerLayer; @property (nonatomic, readwrite) UIScrollView *scrollView; @property (nonatomic, readwrite) UIImageView *pointerImageView; - +@property (nonatomic, assign) BOOL isSetValued; @end @implementation CRRulerControl @@ -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]; } @@ -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 @@ -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]; } @@ -469,4 +475,4 @@ - (CGPoint)offsetForMarkType:(CRRulerMarkType)markType { return CGPointZero; } -@end \ No newline at end of file +@end