diff --git a/SDPhotoBrowser.xcodeproj/project.pbxproj b/SDPhotoBrowser.xcodeproj/project.pbxproj
index 5c9d98d..ab31557 100755
--- a/SDPhotoBrowser.xcodeproj/project.pbxproj
+++ b/SDPhotoBrowser.xcodeproj/project.pbxproj
@@ -419,6 +419,9 @@
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = GSD;
TargetAttributes = {
+ 9973FAAD1A824A1E0089A512 = {
+ DevelopmentTeam = PBXMZG3489;
+ };
9973FACE1A824A1F0089A512 = {
TestTargetID = 9973FAAD1A824A1E0089A512;
};
@@ -615,6 +618,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
+ DEVELOPMENT_TEAM = PBXMZG3489;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SDPhotoBrowser/Others/SDPhotoBrowser-Prefix.pch";
INFOPLIST_FILE = "SDPhotoBrowser/Others/SDPhotoBrowser-Info.plist";
@@ -629,6 +633,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
+ DEVELOPMENT_TEAM = PBXMZG3489;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SDPhotoBrowser/Others/SDPhotoBrowser-Prefix.pch";
INFOPLIST_FILE = "SDPhotoBrowser/Others/SDPhotoBrowser-Info.plist";
diff --git a/SDPhotoBrowser.xcodeproj/project.xcworkspace/xcuserdata/DRAGELEC.xcuserdatad/UserInterfaceState.xcuserstate b/SDPhotoBrowser.xcodeproj/project.xcworkspace/xcuserdata/DRAGELEC.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..bd11a21
Binary files /dev/null and b/SDPhotoBrowser.xcodeproj/project.xcworkspace/xcuserdata/DRAGELEC.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/SDPhotoBrowser.xcodeproj/xcuserdata/DRAGELEC.xcuserdatad/xcschemes/SDPhotoBrowser.xcscheme b/SDPhotoBrowser.xcodeproj/xcuserdata/DRAGELEC.xcuserdatad/xcschemes/SDPhotoBrowser.xcscheme
new file mode 100644
index 0000000..7a64420
--- /dev/null
+++ b/SDPhotoBrowser.xcodeproj/xcuserdata/DRAGELEC.xcuserdatad/xcschemes/SDPhotoBrowser.xcscheme
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SDPhotoBrowser.xcodeproj/xcuserdata/DRAGELEC.xcuserdatad/xcschemes/xcschememanagement.plist b/SDPhotoBrowser.xcodeproj/xcuserdata/DRAGELEC.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..31b4b30
--- /dev/null
+++ b/SDPhotoBrowser.xcodeproj/xcuserdata/DRAGELEC.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,27 @@
+
+
+
+
+ SchemeUserState
+
+ SDPhotoBrowser.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 9973FAAD1A824A1E0089A512
+
+ primary
+
+
+ 9973FACE1A824A1F0089A512
+
+ primary
+
+
+
+
+
diff --git a/SDPhotoBrowser/SDPhotoBrowser/SDPhotoBrowser.m b/SDPhotoBrowser/SDPhotoBrowser/SDPhotoBrowser.m
index 1a420e2..a756a65 100755
--- a/SDPhotoBrowser/SDPhotoBrowser/SDPhotoBrowser.m
+++ b/SDPhotoBrowser/SDPhotoBrowser/SDPhotoBrowser.m
@@ -23,6 +23,9 @@
// =============================================
+// 防止数组越界
+#define kIndex(index) index <= _scrollView.subviews.count - 1 ? index : _scrollView.subviews.count - 1
+
@implementation SDPhotoBrowser
{
UIScrollView *_scrollView;
@@ -87,7 +90,7 @@ - (void)setupToolbars
- (void)saveImage
{
int index = _scrollView.contentOffset.x / _scrollView.bounds.size.width;
- UIImageView *currentImageView = _scrollView.subviews[index];
+ UIImageView *currentImageView = _scrollView.subviews[kIndex(index)];
UIImageWriteToSavedPhotosAlbum(currentImageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
@@ -156,7 +159,7 @@ - (void)setupScrollView
// 加载图片
- (void)setupImageOfImageViewForIndex:(NSInteger)index
{
- SDBrowserImageView *imageView = _scrollView.subviews[index];
+ SDBrowserImageView *imageView = _scrollView.subviews[kIndex(index)];
self.currentImageIndex = index;
if (imageView.hasLoadedImage) return;
if ([self highQualityImageURLForIndex:index]) {
@@ -342,7 +345,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
CGFloat margin = 150;
CGFloat x = scrollView.contentOffset.x;
if ((x - index * self.bounds.size.width) > margin || (x - index * self.bounds.size.width) < - margin) {
- SDBrowserImageView *imageView = _scrollView.subviews[index];
+ SDBrowserImageView *imageView = _scrollView.subviews[kIndex(index)];
if (imageView.isScaled) {
[UIView animateWithDuration:0.5 animations:^{
imageView.transform = CGAffineTransformIdentity;
@@ -354,7 +357,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
if (!_willDisappear) {
- _indexLabel.text = [NSString stringWithFormat:@"%d/%ld", index + 1, (long)self.imageCount];
+ // 当前图片索引不能超过图片数量
+ _indexLabel.text = [NSString stringWithFormat:@"%d/%ld", index < _scrollView.subviews.count ? index + 1 : index, (long)self.imageCount];
}
[self setupImageOfImageViewForIndex:index];
}