Skip to content

Commit

Permalink
Update CLZoomingImageView
Browse files Browse the repository at this point in the history
  • Loading branch information
yackle committed Jan 16, 2014
1 parent 84d21a8 commit 5f76aba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Classes/CLZoomingImageView/CLZoomingImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

@interface CLZoomingImageView : UIView

@property (nonatomic, readonly) UIScrollView *scrollView;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, readonly) BOOL isViewing;

- (void)setImageView:(UIImageView *)imageView;

@end
25 changes: 17 additions & 8 deletions Classes/CLZoomingImageView/CLZoomingImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ @interface CLZoomingImageView()

@implementation CLZoomingImageView
{
UIImageView *_imageView;

UIScrollView *_scrollView;
UIView *_containerView;
}
Expand Down Expand Up @@ -53,26 +51,36 @@ - (void)customInit

#pragma mark- Properties

- (UIScrollView*)scrollView
{
return _scrollView;
}

- (UIImage*)image
{
return _imageView.image;
}

- (void)setImage:(UIImage *)image
{
if(_imageView==nil){
if(self.imageView==nil){
self.imageView = [UIImageView new];
self.imageView.clipsToBounds = YES;
}
_imageView.image = image;
self.imageView.image = image;

CGFloat scale = [[UIScreen mainScreen] scale];
_imageView.bounds = CGRectMake(0, 0, image.size.width / scale, image.size.height / scale);
CGSize size = (self.imageView.image) ? self.imageView.image.size : _containerView.frame.size;
CGFloat ratio = MIN(_scrollView.frame.size.width / size.width, _scrollView.frame.size.height / size.height);
CGFloat W = ratio * size.width;
CGFloat H = ratio * size.height;
self.imageView.frame = CGRectMake(0, 0, W, H);

_scrollView.zoomScale = 1;
_scrollView.contentOffset = CGPointZero;
_containerView.bounds = _imageView.bounds;

[self resetZoomScale];
_scrollView.zoomScale = _scrollView.minimumZoomScale;
[self scrollViewDidZoom:_scrollView];
}

Expand All @@ -91,6 +99,7 @@ - (void)setImageView:(UIImageView *)imageView
_containerView.bounds = _imageView.bounds;

[self resetZoomScale];
_scrollView.zoomScale = _scrollView.minimumZoomScale;
[self scrollViewDidZoom:_scrollView];
}
}
Expand Down Expand Up @@ -122,8 +131,8 @@ - (void)scrollViewDidZoom:(UIScrollView *)scrollView

- (void)resetZoomScale
{
CGFloat Rw = _scrollView.frame.size.width / _imageView.frame.size.width;
CGFloat Rh = _scrollView.frame.size.height / _imageView.frame.size.height;
CGFloat Rw = _scrollView.frame.size.width / self.imageView.frame.size.width;
CGFloat Rh = _scrollView.frame.size.height / self.imageView.frame.size.height;

//CGFloat scale = [[UIScreen mainScreen] scale];
CGFloat scale = 1;
Expand Down

0 comments on commit 5f76aba

Please sign in to comment.