From 73d586e4e66545b35aff90ff4f0bc386e7693879 Mon Sep 17 00:00:00 2001 From: Roman Zhukov Date: Tue, 14 Jun 2016 17:38:14 +0700 Subject: [PATCH] Added a delegate protocol for user's finishing of interaction --- HCSStarRatingView/HCSStarRatingView.h | 10 ++++++++++ HCSStarRatingView/HCSStarRatingView.m | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/HCSStarRatingView/HCSStarRatingView.h b/HCSStarRatingView/HCSStarRatingView.h index 007ab69..5aec6a7 100644 --- a/HCSStarRatingView/HCSStarRatingView.h +++ b/HCSStarRatingView/HCSStarRatingView.h @@ -24,6 +24,8 @@ typedef BOOL(^HCSStarRatingViewShouldBeginGestureRecognizerBlock)(UIGestureRecognizer *gestureRecognizer); +@protocol HCSStarRatingViewDelegate; + IB_DESIGNABLE @interface HCSStarRatingView : UIControl @property (nonatomic) IBInspectable NSUInteger maximumValue; @@ -42,5 +44,13 @@ IB_DESIGNABLE @property (nonatomic, strong) IBInspectable UIImage *emptyStarImage; @property (nonatomic, strong) IBInspectable UIImage *halfStarImage; @property (nonatomic, strong) IBInspectable UIImage *filledStarImage; + +@property (nonatomic, weak) IBOutlet id delegate; @end +@protocol HCSStarRatingViewDelegate + +@optional +- (void)userFinishedRatingOnView:(HCSStarRatingView*)ratingView withRating:(CGFloat)value; + +@end \ No newline at end of file diff --git a/HCSStarRatingView/HCSStarRatingView.m b/HCSStarRatingView/HCSStarRatingView.m index 9a3fea8..7bd2bf7 100644 --- a/HCSStarRatingView/HCSStarRatingView.m +++ b/HCSStarRatingView/HCSStarRatingView.m @@ -377,6 +377,12 @@ - (void)_handleTouch:(UITouch *)touch { [self setValue:value sendValueChangedAction:_continuous]; } +-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { + if ([self.delegate respondsToSelector:@selector(userFinishedRatingOnView:withRating:)]) { + [self.delegate userFinishedRatingOnView:self withRating:self.value]; + } +} + #pragma mark - First responder - (BOOL)canBecomeFirstResponder {