Skip to content

Commit

Permalink
[photos] When photos are loading, show an activity indicator view.
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Nov 9, 2012
1 parent 36c4ef2 commit 56a9082
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/photos/src/NIPhotoAlbumScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ - (void)willDisplayPage:(NIPhotoScrollView *)page {
originalPhotoDimensions: &originalPhotoDimensions];

page.photoDimensions = originalPhotoDimensions;
page.loading = isLoading;

if (nil == image) {
page.zoomingIsEnabled = NO;
Expand Down Expand Up @@ -178,6 +179,7 @@ - (void)didLoadPhoto: (UIImage *)image

// Only replace the photo if it's of a higher quality than one we're already showing.
if (photoSize > page.photoSize) {
page.loading = NO;
[page setImage:image photoSize:photoSize];

page.zoomingIsEnabled = ([self isZoomingEnabled]
Expand Down
2 changes: 2 additions & 0 deletions src/photos/src/NIPhotoScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
UIImageView* _imageView;
// The scroll view.
NICenteringScrollView* _scrollView;
UIActivityIndicatorView* _loadingView;

// Photo Information
NIPhotoScrollViewPhotoSize _photoSize;
Expand Down Expand Up @@ -63,6 +64,7 @@
- (UIImage *)image;
- (NIPhotoScrollViewPhotoSize)photoSize;
- (void)setImage:(UIImage *)image photoSize:(NIPhotoScrollViewPhotoSize)photoSize;
@property (nonatomic, assign, getter = isLoading) BOOL loading;

@property (nonatomic, readwrite, assign) NSInteger pageIndex;
@property (nonatomic, readwrite, assign) CGSize photoDimensions;
Expand Down
16 changes: 16 additions & 0 deletions src/photos/src/NIPhotoScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ - (id)initWithFrame:(CGRect)frame {
_scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleHeight);

_loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[_loadingView sizeToFit];
_loadingView.frame = NIFrameOfCenteredViewWithinView(_loadingView, self);
_loadingView.autoresizingMask = UIViewAutoresizingFlexibleMargins;

// We implement viewForZoomingInScrollView: and return the image view for zooming.
_scrollView.delegate = self;

Expand All @@ -135,6 +140,7 @@ - (id)initWithFrame:(CGRect)frame {

[_scrollView addSubview:_imageView];
[self addSubview:_scrollView];
[self addSubview:_loadingView];
}
return self;
}
Expand Down Expand Up @@ -287,6 +293,16 @@ - (void)setImage:(UIImage *)image photoSize:(NIPhotoScrollViewPhotoSize)photoSiz
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)setLoading:(BOOL)loading {
if (loading) {
[_loadingView startAnimating];
} else {
[_loadingView stopAnimating];
}
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (UIImage *)image {
return _imageView.image;
Expand Down

0 comments on commit 56a9082

Please sign in to comment.