Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

2 participants

@kwent

Add a boolean value to check if clock is started or not. If already started and start method called -> Not Restart Clock Animation

Rousseau Quentin Add a boolean value to check if clock is started or not. If already s…
…tarted and start method called -> Not Restart Clock Animation
dd480ea
@paulsamuels
Owner

Hey thanks for the pull request.

Is there any specific reason/use case for adding the isStarted ivar that you are taking advantage off?

My aim is to expose as little state as possible and the addition of this ivar seems like it could be limited to the visibility of just the implementation or completely removed with a guard check like this...

if (self.clockUpdateTimer) {
  return;
}

Does this simpler change work for your use case?

@kwent

Indeed your proposition seems better that mine. I just wanted to protect clock animations with a multiple start method call.

@paulsamuels
Owner

Thanks for taking the time to look at the source - I've implemented the fix on master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2013
  1. Add a boolean value to check if clock is started or not. If already s…

    Rousseau Quentin authored
    …tarted and start method called -> Not Restart Clock Animation
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.