diff --git a/Classes/BEMAnalogClockView.h b/Classes/BEMAnalogClockView.h index 16aac50..03faed5 100644 --- a/Classes/BEMAnalogClockView.h +++ b/Classes/BEMAnalogClockView.h @@ -32,7 +32,7 @@ //------------------------------------------------------------------------------------// /// BEMAnalogClockView delegate object is essential to the clock. The delegate provides the clock with data and various parameters. The delegate can be set from the interface or from code. -@property (nonatomic, weak) id delegate; +@property (nonatomic, assign) IBOutlet id delegate; //------------------------------------------------------------------------------------// diff --git a/Classes/BEMAnalogClockView.m b/Classes/BEMAnalogClockView.m index eedf841..23e48df 100644 --- a/Classes/BEMAnalogClockView.m +++ b/Classes/BEMAnalogClockView.m @@ -196,9 +196,11 @@ - (void)layoutSubviews { [panView addGestureRecognizer:panGesture]; } + if ([self.delegate respondsToSelector:@selector(currentTimeOnClock:Hours:Minutes:Seconds:)]) { [self.delegate currentTimeOnClock:self Hours:[NSString stringWithFormat:@"%li", (long)self.hours] Minutes:[NSString stringWithFormat:@"%li", (long)self.minutes] Seconds:[NSString stringWithFormat:@"%li", (long)self.seconds]]; + } shouldUpdateSubviews = NO; - + if ([self.delegate respondsToSelector:@selector(clockDidFinishLoading:)]) [self.delegate clockDidFinishLoading:self]; } @@ -215,7 +217,9 @@ - (void)updateEverySecond { [self timeFormatVerification]; [self.animationDelegate rotateHand:self.secondHand rotationDegree:[self degreesFromMinutes:self.seconds]]; + if ([self.delegate respondsToSelector:@selector(currentTimeOnClock:Hours:Minutes:Seconds:)]) { [self.delegate currentTimeOnClock:self Hours:[NSString stringWithFormat:@"%li", (long)self.hours] Minutes:[NSString stringWithFormat:@"%li", (long)self.minutes] Seconds:[NSString stringWithFormat:@"%li", (long)self.seconds]]; + } } } } @@ -246,8 +250,9 @@ - (void)updateTimeAnimated:(BOOL)animated { self.hourHand.transform = CGAffineTransformMakeRotation(([self degreesFromHour:self.hours andMinutes:self.minutes])*(M_PI/180)); self.secondHand.transform = CGAffineTransformMakeRotation(([self degreesFromMinutes:self.seconds])*(M_PI/180)); } - + if ([self.delegate respondsToSelector:@selector(currentTimeOnClock:Hours:Minutes:Seconds:)]) { [self.delegate currentTimeOnClock:self Hours:[NSString stringWithFormat:@"%li", (long)self.hours] Minutes:[NSString stringWithFormat:@"%li", (long)self.minutes] Seconds:[NSString stringWithFormat:@"%li", (long)self.seconds]]; + } } - (void)setClockToCurrentTimeAnimated:(BOOL)animated { @@ -274,8 +279,9 @@ - (void)setClockToCurrentTimeAnimated:(BOOL)animated { self.hourHand.transform = CGAffineTransformMakeRotation(([self degreesFromHour:self.hours andMinutes:self.minutes])*(M_PI/180)); self.secondHand.transform = CGAffineTransformMakeRotation(([self degreesFromMinutes:self.seconds])*(M_PI/180)); } - + if ([self.delegate respondsToSelector:@selector(currentTimeOnClock:Hours:Minutes:Seconds:)]) { [self.delegate currentTimeOnClock:self Hours:[NSString stringWithFormat:@"%li", (long)self.hours] Minutes:[NSString stringWithFormat:@"%li", (long)self.minutes] Seconds:[NSString stringWithFormat:@"%li", (long)self.seconds]]; + } } - (void)startRealTime { @@ -317,7 +323,9 @@ - (void)handlePan:(UIPanGestureRecognizer *)recognizer { self.minuteHand.transform = CGAffineTransformMakeRotation(angleInRadians + M_PI/2); self.hourHand.transform = CGAffineTransformMakeRotation(([self degreesFromHour:self.hours andMinutes:self.minutes])*(M_PI/180)); - [self.delegate currentTimeOnClock:self Hours:[NSString stringWithFormat:@"%li", (long)self.hours] Minutes:[NSString stringWithFormat:@"%li", (long)self.minutes] Seconds:[NSString stringWithFormat:@"%li", (long)self.seconds]]; + if ([self.delegate respondsToSelector:@selector(currentTimeOnClock:Hours:Minutes:Seconds:)]) { + [self.delegate currentTimeOnClock:self Hours:[NSString stringWithFormat:@"%li", (long)self.hours] Minutes:[NSString stringWithFormat:@"%li", (long)self.minutes] Seconds:[NSString stringWithFormat:@"%li", (long)self.seconds]]; + } } #pragma mark - Conversions/Calculations diff --git a/Sample Project/BEMAnalogClock/Base.lproj/Main.storyboard b/Sample Project/BEMAnalogClock/Base.lproj/Main.storyboard index f4fbcba..36f7a06 100644 --- a/Sample Project/BEMAnalogClock/Base.lproj/Main.storyboard +++ b/Sample Project/BEMAnalogClock/Base.lproj/Main.storyboard @@ -1,7 +1,7 @@ - + - + @@ -42,6 +42,9 @@ + + + @@ -94,4 +97,4 @@ - \ No newline at end of file +