Add a boolean value to check if clock is started or not #2

Closed
wants to merge 1 commit into from
View
1 AnalogClockWithImages/PSAnalogClockView.h
@@ -22,6 +22,7 @@ typedef enum {
@interface PSAnalogClockView : UIView
+@property (nonatomic) BOOL isStarted;
@property (nonatomic, strong) UIImage *secondHandImage;
@property (nonatomic, strong) UIImage *minuteHandImage;
@property (nonatomic, strong) UIImage *hourHandImage;
View
17 AnalogClockWithImages/PSAnalogClockView.m
@@ -99,17 +99,22 @@ - (void)addImageViews
- (void)start
{
- self.clockUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
- target:self
- selector:@selector(updateClockTimeAnimated:)
- userInfo:nil
- repeats:YES];
- [self updateClockTimeAnimated:NO];
+ if(!isStarted)
+ {
+ self.clockUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
+ target:self
+ selector:@selector(updateClockTimeAnimated:)
+ userInfo:nil
+ repeats:YES];
+ [self updateClockTimeAnimated:NO];
+ isStarted = YES;
+ }
}
- (void)stop
{
[self.clockUpdateTimer invalidate]; self.clockUpdateTimer = nil;
+ isStarted = NO;
}
- (void)updateClockTimeAnimated:(BOOL)animated