Skip to content

Commit

Permalink
Add asynchronous setImage: with completion block
Browse files Browse the repository at this point in the history
  • Loading branch information
dingbat committed Jul 16, 2013
1 parent 61b5419 commit 1c526ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions FaceImageView/FaceImageView.h
Expand Up @@ -15,4 +15,6 @@

@property (nonatomic, readonly) int numberOfFacesDetected;

- (void) setImage:(UIImage *)image completion:(void(^)(void))block;

@end
16 changes: 16 additions & 0 deletions FaceImageView/FaceImageView.m
Expand Up @@ -86,6 +86,22 @@ - (void) calculateCentroidOfFaceLocations
_centroid = centroid;
}

- (void) setImage:(UIImage *)image completion:(void(^)(void))block
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
[self setImage:image];

dispatch_async(dispatch_get_main_queue(), ^
{
[self setNeedsDisplay];

if (block)
block();
});
});
}

- (void) setImage:(UIImage *)image
{
_image = image;
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Expand Up @@ -28,6 +28,12 @@ imageView.image = <UIImage>;
[self.view addSubview:imageView];
```

It may also be wise to set the image asynchronously, as face detection can sometimes take a second:

```
[imageView setImage:<UIImage> completion:^{}];
```

Demo App
---------

Expand Down

0 comments on commit 1c526ce

Please sign in to comment.