Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SDPhotoBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = GSD;
TargetAttributes = {
9973FAAD1A824A1E0089A512 = {
DevelopmentTeam = PBXMZG3489;
};
9973FACE1A824A1F0089A512 = {
TestTargetID = 9973FAAD1A824A1E0089A512;
};
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9973FAAD1A824A1E0089A512"
BuildableName = "SDPhotoBrowser.app"
BlueprintName = "SDPhotoBrowser"
ReferencedContainer = "container:SDPhotoBrowser.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9973FACE1A824A1F0089A512"
BuildableName = "SDPhotoBrowserTests.xctest"
BlueprintName = "SDPhotoBrowserTests"
ReferencedContainer = "container:SDPhotoBrowser.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9973FAAD1A824A1E0089A512"
BuildableName = "SDPhotoBrowser.app"
BlueprintName = "SDPhotoBrowser"
ReferencedContainer = "container:SDPhotoBrowser.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9973FAAD1A824A1E0089A512"
BuildableName = "SDPhotoBrowser.app"
BlueprintName = "SDPhotoBrowser"
ReferencedContainer = "container:SDPhotoBrowser.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9973FAAD1A824A1E0089A512"
BuildableName = "SDPhotoBrowser.app"
BlueprintName = "SDPhotoBrowser"
ReferencedContainer = "container:SDPhotoBrowser.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SDPhotoBrowser.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>9973FAAD1A824A1E0089A512</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>9973FACE1A824A1F0089A512</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
12 changes: 8 additions & 4 deletions SDPhotoBrowser/SDPhotoBrowser/SDPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

// =============================================

// 防止数组越界
#define kIndex(index) index <= _scrollView.subviews.count - 1 ? index : _scrollView.subviews.count - 1

@implementation SDPhotoBrowser
{
UIScrollView *_scrollView;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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;
Expand All @@ -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];
}
Expand Down