Skip to content

Commit

Permalink
fix the bug of unvalid currentIndex and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
greedbell committed Jun 3, 2016
1 parent 28120e9 commit 3f83380
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 170 deletions.
39 changes: 39 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 基础样式
BasedOnStyle: LLVM

# 缩进宽度
IndentWidth: 4

# 圆括号的换行方式
BreakBeforeBraces: Attach

# 支持一行的if
AllowShortIfStatementsOnASingleLine: true

# switch的case缩进
IndentCaseLabels: true

# 针对OC的block的缩进宽度
ObjCBlockIndentWidth: 4

# 针对OC,属性名后加空格
ObjCSpaceAfterProperty: true

# 每行字符的长度
ColumnLimit: 0

# 注释对齐
AlignTrailingComments: true

# 括号后加空格
SpaceAfterCStyleCast: true

# 不在小括号里加空格
SpacesInParentheses: false

# 不在中括号里加空格
SpacesInSquareBrackets: false

# 是否用tab
UseTab: Never

38 changes: 18 additions & 20 deletions Example/Example/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,35 @@ @interface ViewController ()

@implementation ViewController

- (void)viewDidLoad
{
- (void)viewDidLoad {
[super viewDidLoad];

NSURL *url = [NSURL URLWithString:@"http://h.hiphotos.baidu.com/image/w%3D2048/sign=bf43f947be315c6043956cefb989ca13/c83d70cf3bc79f3da761b162b8a1cd11738b29db.jpg"];
NSURL *url1 = [NSURL URLWithString:@"http://h.hiphotos.baidu.com/image/w%3D2048/sign=bf43f947be315c6043956cefb989ca13/c83d70cf3bc79f3da761b1"];
_srcStringArray = @[[UIImage imageNamed:@"qq"],
[UIImage imageNamed:@"pengyouquan"],
[UIImage imageNamed:@"qq"],
[UIImage imageNamed:@"pengyouquan"],
[UIImage imageNamed:@"qq"],
[UIImage imageNamed:@"pengyouquan"],
url1,
[UIImage imageNamed:@"pengyouquan"],
url
];
_srcStringArray = @[ [UIImage imageNamed:@"qq"],
[UIImage imageNamed:@"pengyouquan"],
[UIImage imageNamed:@"qq"],
[UIImage imageNamed:@"pengyouquan"],
[UIImage imageNamed:@"qq"],
[UIImage imageNamed:@"pengyouquan"],
url1,
[UIImage imageNamed:@"pengyouquan"],
url ];
NSMutableArray *temp = [NSMutableArray array];
[_srcStringArray enumerateObjectsUsingBlock:^(NSObject *src, NSUInteger idx, BOOL *stop) {
GRPhotoBrowserItem *item = [[GRPhotoBrowserItem alloc] init];
if([src isKindOfClass:[UIImage class]]){
item.image = (UIImage *)src;
if ([src isKindOfClass:[UIImage class]]) {
item.image = (UIImage *) src;
item.placeholderImage = nil;
[temp addObject:item];
} else if ([src isKindOfClass:[NSURL class]]){
item.url = (NSURL *)src;
} else if ([src isKindOfClass:[NSURL class]]) {
item.url = (NSURL *) src;
item.placeholderImage = [UIImage imageNamed:@"pengyouquan"];
[temp addObject:item];
}
}];
_photoItemArray = temp;

UIButton *btn = [[UIButton alloc] init];
[btn setTitle:@"show" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor redColor]];
Expand All @@ -53,11 +51,11 @@ - (void)viewDidLoad
[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
}

- (void)click
{
- (void)click {
GRPhotoBrowserViewController *viewController = [[GRPhotoBrowserViewController alloc] init];
viewController.photoItemsArray = _photoItemArray;
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
viewController.currentIndex = 2;
[self presentViewController:viewController animated:YES completion:nil];
}

Expand Down
6 changes: 3 additions & 3 deletions GreedPhotoBrowser.podspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Pod::Spec.new do |s|

s.name = "GreedPhotoBrowser"
s.version = "0.0.1"
s.version = "0.0.3"
s.summary = "a photo browser for iOS"
s.description = %{ a photo browser for iOS }
s.description = %{this is a photo browser for iOS }
s.homepage = "https://github.com/greedlab/GreedPhotoBrowser"
s.license = "MIT"
s.author = { "Bell" => "[email protected]" }
s.platform = :ios, "6.0"
s.source = { :git => "https://github.com/greedlab/GreedPhotoBrowser.git", :tag => s.version }
s.source_files = "GreedPhotoBrowser", "GreedPhotoBrowser/*.{h,m}"
s.frameworks = "Foundation","UIKIT"
s.frameworks = "Foundation","UIKit"
s.dependency 'SDWebImage'
s.dependency 'Masonry'
s.requires_arc = true
Expand Down
3 changes: 2 additions & 1 deletion GreedPhotoBrowser/GRPhotoBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#ifndef GRPhotoBrowser_h
#define GRPhotoBrowser_h

#import "GRPhotoBrowserViewController.h"
#import "GRPhotoBrowserItem.h"
#import "GRPhotoBrowserView.h"
#import "GRPhotoBrowserViewController.h"

#endif /* GRPhotoBrowser_h */
4 changes: 1 addition & 3 deletions GreedPhotoBrowser/GRPhotoBrowserSingleView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#import "Masonry.h"
#import "GRPhotoBrowserWaitingView.h"

@interface GRPhotoBrowserSingleView : UIView
<UIGestureRecognizerDelegate>
{
@interface GRPhotoBrowserSingleView : UIView <UIGestureRecognizerDelegate> {
MASConstraint *_imageViewHeightConstraint;
MASConstraint *_imageViewWidthConstraint;
}
Expand Down
86 changes: 41 additions & 45 deletions GreedPhotoBrowser/GRPhotoBrowserSingleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

@implementation GRPhotoBrowserSingleView

- (id)initWithFrame:(CGRect)frame
{
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_scale = 1.0;
Expand All @@ -25,78 +24,76 @@ - (id)initWithFrame:(CGRect)frame

#pragma mark - public

- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(void (^)(BOOL success))completed
{
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(void (^)(BOOL success))completed {
[_waitingView setHidden:NO];
WeakSelf(weakSelf);
[_imageView sd_setImageWithURL:url placeholderImage:placeholder options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {
weakSelf.progress = (CGFloat)receivedSize / expectedSize;
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[_waitingView setHidden:YES];
if (error) {
[_failLabel setHidden:NO];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[_failLabel setHidden:YES];
});
if (completed) {
completed(NO);
}
} else {
_imageView.image = image;
if (completed) {
completed(YES);
}
[_imageView sd_setImageWithURL:url
placeholderImage:placeholder
options:SDWebImageRetryFailed
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
weakSelf.progress = (CGFloat) receivedSize / expectedSize;
}
}];
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[_waitingView setHidden:YES];
if (error) {
[_failLabel setHidden:NO];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[_failLabel setHidden:YES];
});
if (completed) {
completed(NO);
}
} else {
_imageView.image = image;
if (completed) {
completed(YES);
}
}
}];
}

- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
{
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
[self setImageWithURL:url placeholderImage:placeholder completed:nil];
}

- (void)updateForScale:(CGFloat)scale animate:(BOOL)animate
{
- (void)updateForScale:(CGFloat)scale animate:(BOOL)animate {
[_imageViewHeightConstraint setOffset:((scale - 1) * _scrollView.frame.size.height)];
[_imageViewWidthConstraint setOffset:((scale - 1) * _scrollView.frame.size.width)];

if (animate) {
[UIView animateWithDuration:0.3 animations:^{
[_scrollView layoutIfNeeded];
[_scrollView setContentOffset:CGPointMake((_scrollView.contentSize.width - _scrollView.frame.size.width) / 2.0, (_scrollView.contentSize.height - _scrollView.frame.size.height ) / 2.0)];
}];
[UIView animateWithDuration:0.3
animations:^{
[_scrollView layoutIfNeeded];
[_scrollView setContentOffset:CGPointMake((_scrollView.contentSize.width - _scrollView.frame.size.width) / 2.0, (_scrollView.contentSize.height - _scrollView.frame.size.height) / 2.0)];
}];
} else {
[_scrollView layoutIfNeeded];
[_scrollView setContentOffset:CGPointMake((_scrollView.contentSize.width - _scrollView.frame.size.width) / 2.0, (_scrollView.contentSize.height - _scrollView.frame.size.height ) / 2.0)];
[_scrollView setContentOffset:CGPointMake((_scrollView.contentSize.width - _scrollView.frame.size.width) / 2.0, (_scrollView.contentSize.height - _scrollView.frame.size.height) / 2.0)];
}
}

#pragma mark - getter

- (BOOL)isScaled
{
return 1.0 != _scale;
- (BOOL)isScaled {
return 1.0 != _scale;
}

#pragma mark - setter

- (void)setProgress:(CGFloat)progress
{
- (void)setProgress:(CGFloat)progress {
if (_progress == progress) {
return;
}
_progress = progress;
_waitingView.progress = progress;
}

- (void)setScale:(CGFloat)scale
{
- (void)setScale:(CGFloat)scale {
[self setScale:scale animate:NO];
}

- (void)setScale:(CGFloat)scale animate:(BOOL)animate
{
- (void)setScale:(CGFloat)scale animate:(BOOL)animate {
if (scale < 0.5 || scale > 2.0 || scale == _scale) {
return;
}
Expand All @@ -106,8 +103,7 @@ - (void)setScale:(CGFloat)scale animate:(BOOL)animate

#pragma mark - action

- (void)zoomImage:(UIPinchGestureRecognizer *)recognizer
{
- (void)zoomImage:(UIPinchGestureRecognizer *)recognizer {
CGFloat scale = recognizer.scale;
CGFloat temp = _scale + (scale - 1);
[self setScale:temp];
Expand All @@ -132,7 +128,7 @@ - (void)initView {
_imageView = imageView;
}
{

GRPhotoBrowserWaitingView *waitingView = [[GRPhotoBrowserWaitingView alloc] init];
waitingView.mode = GRPhotoBrowserWaitingViewProgressMode;
waitingView.hidden = YES;
Expand Down
3 changes: 1 addition & 2 deletions GreedPhotoBrowser/GRPhotoBrowserView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

@end

@interface GRPhotoBrowserView : UIView<UIScrollViewDelegate>
{
@interface GRPhotoBrowserView : UIView <UIScrollViewDelegate> {
BOOL _showed;
CGFloat _viewHeight;
CGFloat _viewWidth;
Expand Down
Loading

0 comments on commit 3f83380

Please sign in to comment.