├── .gitignore ├── ImageScrollView.podspec ├── ImageScrollViewDemo ├── ImageScrollViewDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── ImageScrollViewDemo.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── ImageScrollViewDemo │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Images │ │ ├── dog-0.jpg │ │ ├── dog-1.jpg │ │ ├── dog-2.jpg │ │ ├── dog-3.jpg │ │ └── dog-4.jpg │ ├── Info.plist │ └── ViewController.swift ├── Podfile └── Podfile.lock ├── LICENSE ├── Package.swift ├── README.md ├── ReadMeImages ├── demo.gif └── storyboard-demo.jpeg └── Sources └── ImageScrollView.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/screenshots 64 | -------------------------------------------------------------------------------- /ImageScrollView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'ImageScrollView' 3 | s.version = '1.9.3' 4 | s.summary = 'Zoomable and scrollable image view' 5 | s.homepage = 'https://github.com/huynguyencong/ImageScrollView' 6 | s.license = { :type => 'MIT', :file => 'LICENSE' } 7 | s.source = { :git => 'https://github.com/huynguyencong/ImageScrollView.git', :tag => "#{s.version}" } 8 | s.author = { 'Huy Nguyen Cong' => 'https://github.com/huynguyencong' } 9 | s.ios.deployment_target = '13.0' 10 | s.source_files = 'Sources/*.{swift}' 11 | s.requires_arc = true 12 | s.swift_versions = ['5.1', '5.2', '5.3'] 13 | end 14 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6157A95D1C8B2E050088D051 /* dog-0.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 6157A9581C8B2E050088D051 /* dog-0.jpg */; }; 11 | 6157A95E1C8B2E050088D051 /* dog-1.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 6157A9591C8B2E050088D051 /* dog-1.jpg */; }; 12 | 6157A95F1C8B2E050088D051 /* dog-2.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 6157A95A1C8B2E050088D051 /* dog-2.jpg */; }; 13 | 6157A9601C8B2E050088D051 /* dog-3.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 6157A95B1C8B2E050088D051 /* dog-3.jpg */; }; 14 | 6157A9611C8B2E050088D051 /* dog-4.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 6157A95C1C8B2E050088D051 /* dog-4.jpg */; }; 15 | 61F313831C8A04710096BF64 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61F313821C8A04710096BF64 /* AppDelegate.swift */; }; 16 | 61F313851C8A04710096BF64 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61F313841C8A04710096BF64 /* ViewController.swift */; }; 17 | 61F313881C8A04710096BF64 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 61F313861C8A04710096BF64 /* Main.storyboard */; }; 18 | 61F3138A1C8A04710096BF64 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 61F313891C8A04710096BF64 /* Assets.xcassets */; }; 19 | 61F3138D1C8A04710096BF64 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 61F3138B1C8A04710096BF64 /* LaunchScreen.storyboard */; }; 20 | E02C9B9990411837848B8AE1 /* Pods_ImageScrollViewDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52A0FB7EA560B9F778B9A2EE /* Pods_ImageScrollViewDemo.framework */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | 0BFEAE319F2581E8B5EDD30B /* Pods-ImageScrollViewDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageScrollViewDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-ImageScrollViewDemo/Pods-ImageScrollViewDemo.release.xcconfig"; sourceTree = ""; }; 25 | 52A0FB7EA560B9F778B9A2EE /* Pods_ImageScrollViewDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ImageScrollViewDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | 58D246FD3F219571C62065EE /* Pods-ImageScrollViewDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageScrollViewDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ImageScrollViewDemo/Pods-ImageScrollViewDemo.debug.xcconfig"; sourceTree = ""; }; 27 | 6157A9581C8B2E050088D051 /* dog-0.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "dog-0.jpg"; sourceTree = ""; }; 28 | 6157A9591C8B2E050088D051 /* dog-1.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "dog-1.jpg"; sourceTree = ""; }; 29 | 6157A95A1C8B2E050088D051 /* dog-2.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "dog-2.jpg"; sourceTree = ""; }; 30 | 6157A95B1C8B2E050088D051 /* dog-3.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "dog-3.jpg"; sourceTree = ""; }; 31 | 6157A95C1C8B2E050088D051 /* dog-4.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "dog-4.jpg"; sourceTree = ""; }; 32 | 61F3137F1C8A04710096BF64 /* ImageScrollViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ImageScrollViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 61F313821C8A04710096BF64 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 34 | 61F313841C8A04710096BF64 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 35 | 61F313871C8A04710096BF64 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 36 | 61F313891C8A04710096BF64 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 37 | 61F3138C1C8A04710096BF64 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 38 | 61F3138E1C8A04710096BF64 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 39 | 7B5BA4BEA28F0ABFBED66522 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 40 | ABEA9732278037A45B8BB744 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 61F3137C1C8A04710096BF64 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | E02C9B9990411837848B8AE1 /* Pods_ImageScrollViewDemo.framework in Frameworks */, 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXFrameworksBuildPhase section */ 53 | 54 | /* Begin PBXGroup section */ 55 | 2CFCADA7D8E42A60443E5796 /* Frameworks */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | 52A0FB7EA560B9F778B9A2EE /* Pods_ImageScrollViewDemo.framework */, 59 | ); 60 | name = Frameworks; 61 | sourceTree = ""; 62 | }; 63 | 6157A9571C8B2DF60088D051 /* Images */ = { 64 | isa = PBXGroup; 65 | children = ( 66 | 6157A9581C8B2E050088D051 /* dog-0.jpg */, 67 | 6157A9591C8B2E050088D051 /* dog-1.jpg */, 68 | 6157A95A1C8B2E050088D051 /* dog-2.jpg */, 69 | 6157A95B1C8B2E050088D051 /* dog-3.jpg */, 70 | 6157A95C1C8B2E050088D051 /* dog-4.jpg */, 71 | ); 72 | name = Images; 73 | path = ImageScrollViewDemo/Images; 74 | sourceTree = ""; 75 | }; 76 | 61F313761C8A04710096BF64 = { 77 | isa = PBXGroup; 78 | children = ( 79 | 61F313811C8A04710096BF64 /* ImageScrollViewDemo */, 80 | 6157A9571C8B2DF60088D051 /* Images */, 81 | 61F313801C8A04710096BF64 /* Products */, 82 | 92D6AE927D01E89282D8D494 /* Pods */, 83 | 2CFCADA7D8E42A60443E5796 /* Frameworks */, 84 | ); 85 | sourceTree = ""; 86 | }; 87 | 61F313801C8A04710096BF64 /* Products */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 61F3137F1C8A04710096BF64 /* ImageScrollViewDemo.app */, 91 | ); 92 | name = Products; 93 | sourceTree = ""; 94 | }; 95 | 61F313811C8A04710096BF64 /* ImageScrollViewDemo */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 61F313821C8A04710096BF64 /* AppDelegate.swift */, 99 | 61F313841C8A04710096BF64 /* ViewController.swift */, 100 | 61F313861C8A04710096BF64 /* Main.storyboard */, 101 | 61F313891C8A04710096BF64 /* Assets.xcassets */, 102 | 61F3138B1C8A04710096BF64 /* LaunchScreen.storyboard */, 103 | 61F3138E1C8A04710096BF64 /* Info.plist */, 104 | ); 105 | path = ImageScrollViewDemo; 106 | sourceTree = ""; 107 | }; 108 | 92D6AE927D01E89282D8D494 /* Pods */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 7B5BA4BEA28F0ABFBED66522 /* Pods.debug.xcconfig */, 112 | ABEA9732278037A45B8BB744 /* Pods.release.xcconfig */, 113 | 58D246FD3F219571C62065EE /* Pods-ImageScrollViewDemo.debug.xcconfig */, 114 | 0BFEAE319F2581E8B5EDD30B /* Pods-ImageScrollViewDemo.release.xcconfig */, 115 | ); 116 | name = Pods; 117 | sourceTree = ""; 118 | }; 119 | /* End PBXGroup section */ 120 | 121 | /* Begin PBXNativeTarget section */ 122 | 61F3137E1C8A04710096BF64 /* ImageScrollViewDemo */ = { 123 | isa = PBXNativeTarget; 124 | buildConfigurationList = 61F313911C8A04710096BF64 /* Build configuration list for PBXNativeTarget "ImageScrollViewDemo" */; 125 | buildPhases = ( 126 | 9330F1AC23541D45F916ABB9 /* [CP] Check Pods Manifest.lock */, 127 | 61F3137B1C8A04710096BF64 /* Sources */, 128 | 61F3137C1C8A04710096BF64 /* Frameworks */, 129 | 61F3137D1C8A04710096BF64 /* Resources */, 130 | 96B1EA2E91EDF0C09241896B /* [CP] Embed Pods Frameworks */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | ); 136 | name = ImageScrollViewDemo; 137 | productName = ImageScrollViewDemo; 138 | productReference = 61F3137F1C8A04710096BF64 /* ImageScrollViewDemo.app */; 139 | productType = "com.apple.product-type.application"; 140 | }; 141 | /* End PBXNativeTarget section */ 142 | 143 | /* Begin PBXProject section */ 144 | 61F313771C8A04710096BF64 /* Project object */ = { 145 | isa = PBXProject; 146 | attributes = { 147 | LastSwiftUpdateCheck = 0720; 148 | LastUpgradeCheck = 1020; 149 | ORGANIZATIONNAME = "Nguyen Cong Huy"; 150 | TargetAttributes = { 151 | 61F3137E1C8A04710096BF64 = { 152 | CreatedOnToolsVersion = 7.2; 153 | LastSwiftMigration = 0900; 154 | }; 155 | }; 156 | }; 157 | buildConfigurationList = 61F3137A1C8A04710096BF64 /* Build configuration list for PBXProject "ImageScrollViewDemo" */; 158 | compatibilityVersion = "Xcode 3.2"; 159 | developmentRegion = English; 160 | hasScannedForEncodings = 0; 161 | knownRegions = ( 162 | English, 163 | en, 164 | Base, 165 | ); 166 | mainGroup = 61F313761C8A04710096BF64; 167 | productRefGroup = 61F313801C8A04710096BF64 /* Products */; 168 | projectDirPath = ""; 169 | projectRoot = ""; 170 | targets = ( 171 | 61F3137E1C8A04710096BF64 /* ImageScrollViewDemo */, 172 | ); 173 | }; 174 | /* End PBXProject section */ 175 | 176 | /* Begin PBXResourcesBuildPhase section */ 177 | 61F3137D1C8A04710096BF64 /* Resources */ = { 178 | isa = PBXResourcesBuildPhase; 179 | buildActionMask = 2147483647; 180 | files = ( 181 | 61F3138D1C8A04710096BF64 /* LaunchScreen.storyboard in Resources */, 182 | 6157A9611C8B2E050088D051 /* dog-4.jpg in Resources */, 183 | 6157A95F1C8B2E050088D051 /* dog-2.jpg in Resources */, 184 | 61F3138A1C8A04710096BF64 /* Assets.xcassets in Resources */, 185 | 61F313881C8A04710096BF64 /* Main.storyboard in Resources */, 186 | 6157A9601C8B2E050088D051 /* dog-3.jpg in Resources */, 187 | 6157A95D1C8B2E050088D051 /* dog-0.jpg in Resources */, 188 | 6157A95E1C8B2E050088D051 /* dog-1.jpg in Resources */, 189 | ); 190 | runOnlyForDeploymentPostprocessing = 0; 191 | }; 192 | /* End PBXResourcesBuildPhase section */ 193 | 194 | /* Begin PBXShellScriptBuildPhase section */ 195 | 9330F1AC23541D45F916ABB9 /* [CP] Check Pods Manifest.lock */ = { 196 | isa = PBXShellScriptBuildPhase; 197 | buildActionMask = 2147483647; 198 | files = ( 199 | ); 200 | inputPaths = ( 201 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 202 | "${PODS_ROOT}/Manifest.lock", 203 | ); 204 | name = "[CP] Check Pods Manifest.lock"; 205 | outputPaths = ( 206 | "$(DERIVED_FILE_DIR)/Pods-ImageScrollViewDemo-checkManifestLockResult.txt", 207 | ); 208 | runOnlyForDeploymentPostprocessing = 0; 209 | shellPath = /bin/sh; 210 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 211 | showEnvVarsInLog = 0; 212 | }; 213 | 96B1EA2E91EDF0C09241896B /* [CP] Embed Pods Frameworks */ = { 214 | isa = PBXShellScriptBuildPhase; 215 | buildActionMask = 2147483647; 216 | files = ( 217 | ); 218 | inputPaths = ( 219 | "${PODS_ROOT}/Target Support Files/Pods-ImageScrollViewDemo/Pods-ImageScrollViewDemo-frameworks.sh", 220 | "${BUILT_PRODUCTS_DIR}/ImageScrollView/ImageScrollView.framework", 221 | ); 222 | name = "[CP] Embed Pods Frameworks"; 223 | outputPaths = ( 224 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ImageScrollView.framework", 225 | ); 226 | runOnlyForDeploymentPostprocessing = 0; 227 | shellPath = /bin/sh; 228 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ImageScrollViewDemo/Pods-ImageScrollViewDemo-frameworks.sh\"\n"; 229 | showEnvVarsInLog = 0; 230 | }; 231 | /* End PBXShellScriptBuildPhase section */ 232 | 233 | /* Begin PBXSourcesBuildPhase section */ 234 | 61F3137B1C8A04710096BF64 /* Sources */ = { 235 | isa = PBXSourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | 61F313851C8A04710096BF64 /* ViewController.swift in Sources */, 239 | 61F313831C8A04710096BF64 /* AppDelegate.swift in Sources */, 240 | ); 241 | runOnlyForDeploymentPostprocessing = 0; 242 | }; 243 | /* End PBXSourcesBuildPhase section */ 244 | 245 | /* Begin PBXVariantGroup section */ 246 | 61F313861C8A04710096BF64 /* Main.storyboard */ = { 247 | isa = PBXVariantGroup; 248 | children = ( 249 | 61F313871C8A04710096BF64 /* Base */, 250 | ); 251 | name = Main.storyboard; 252 | sourceTree = ""; 253 | }; 254 | 61F3138B1C8A04710096BF64 /* LaunchScreen.storyboard */ = { 255 | isa = PBXVariantGroup; 256 | children = ( 257 | 61F3138C1C8A04710096BF64 /* Base */, 258 | ); 259 | name = LaunchScreen.storyboard; 260 | sourceTree = ""; 261 | }; 262 | /* End PBXVariantGroup section */ 263 | 264 | /* Begin XCBuildConfiguration section */ 265 | 61F3138F1C8A04710096BF64 /* Debug */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | ALWAYS_SEARCH_USER_PATHS = NO; 269 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 270 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 271 | CLANG_CXX_LIBRARY = "libc++"; 272 | CLANG_ENABLE_MODULES = YES; 273 | CLANG_ENABLE_OBJC_ARC = YES; 274 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 275 | CLANG_WARN_BOOL_CONVERSION = YES; 276 | CLANG_WARN_COMMA = YES; 277 | CLANG_WARN_CONSTANT_CONVERSION = YES; 278 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 279 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 280 | CLANG_WARN_EMPTY_BODY = YES; 281 | CLANG_WARN_ENUM_CONVERSION = YES; 282 | CLANG_WARN_INFINITE_RECURSION = YES; 283 | CLANG_WARN_INT_CONVERSION = YES; 284 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 285 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 286 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 287 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 288 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 289 | CLANG_WARN_STRICT_PROTOTYPES = YES; 290 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 291 | CLANG_WARN_UNREACHABLE_CODE = YES; 292 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 293 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 294 | COPY_PHASE_STRIP = NO; 295 | DEBUG_INFORMATION_FORMAT = dwarf; 296 | ENABLE_STRICT_OBJC_MSGSEND = YES; 297 | ENABLE_TESTABILITY = YES; 298 | GCC_C_LANGUAGE_STANDARD = gnu99; 299 | GCC_DYNAMIC_NO_PIC = NO; 300 | GCC_NO_COMMON_BLOCKS = YES; 301 | GCC_OPTIMIZATION_LEVEL = 0; 302 | GCC_PREPROCESSOR_DEFINITIONS = ( 303 | "DEBUG=1", 304 | "$(inherited)", 305 | ); 306 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 307 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 308 | GCC_WARN_UNDECLARED_SELECTOR = YES; 309 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 310 | GCC_WARN_UNUSED_FUNCTION = YES; 311 | GCC_WARN_UNUSED_VARIABLE = YES; 312 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 313 | MTL_ENABLE_DEBUG_INFO = YES; 314 | ONLY_ACTIVE_ARCH = YES; 315 | SDKROOT = iphoneos; 316 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 317 | SWIFT_VERSION = 5.0; 318 | TARGETED_DEVICE_FAMILY = "1,2"; 319 | }; 320 | name = Debug; 321 | }; 322 | 61F313901C8A04710096BF64 /* Release */ = { 323 | isa = XCBuildConfiguration; 324 | buildSettings = { 325 | ALWAYS_SEARCH_USER_PATHS = NO; 326 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 327 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 328 | CLANG_CXX_LIBRARY = "libc++"; 329 | CLANG_ENABLE_MODULES = YES; 330 | CLANG_ENABLE_OBJC_ARC = YES; 331 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 332 | CLANG_WARN_BOOL_CONVERSION = YES; 333 | CLANG_WARN_COMMA = YES; 334 | CLANG_WARN_CONSTANT_CONVERSION = YES; 335 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 336 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 337 | CLANG_WARN_EMPTY_BODY = YES; 338 | CLANG_WARN_ENUM_CONVERSION = YES; 339 | CLANG_WARN_INFINITE_RECURSION = YES; 340 | CLANG_WARN_INT_CONVERSION = YES; 341 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 342 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 343 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 344 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 345 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 346 | CLANG_WARN_STRICT_PROTOTYPES = YES; 347 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 348 | CLANG_WARN_UNREACHABLE_CODE = YES; 349 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 350 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 351 | COPY_PHASE_STRIP = NO; 352 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 353 | ENABLE_NS_ASSERTIONS = NO; 354 | ENABLE_STRICT_OBJC_MSGSEND = YES; 355 | GCC_C_LANGUAGE_STANDARD = gnu99; 356 | GCC_NO_COMMON_BLOCKS = YES; 357 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 358 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 359 | GCC_WARN_UNDECLARED_SELECTOR = YES; 360 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 361 | GCC_WARN_UNUSED_FUNCTION = YES; 362 | GCC_WARN_UNUSED_VARIABLE = YES; 363 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 364 | MTL_ENABLE_DEBUG_INFO = NO; 365 | SDKROOT = iphoneos; 366 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 367 | SWIFT_VERSION = 5.0; 368 | TARGETED_DEVICE_FAMILY = "1,2"; 369 | VALIDATE_PRODUCT = YES; 370 | }; 371 | name = Release; 372 | }; 373 | 61F313921C8A04710096BF64 /* Debug */ = { 374 | isa = XCBuildConfiguration; 375 | baseConfigurationReference = 58D246FD3F219571C62065EE /* Pods-ImageScrollViewDemo.debug.xcconfig */; 376 | buildSettings = { 377 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 378 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 379 | INFOPLIST_FILE = ImageScrollViewDemo/Info.plist; 380 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 381 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 382 | PRODUCT_BUNDLE_IDENTIFIER = com.nch.ImageScrollViewDemo; 383 | PRODUCT_NAME = "$(TARGET_NAME)"; 384 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 385 | SWIFT_VERSION = 5.0; 386 | }; 387 | name = Debug; 388 | }; 389 | 61F313931C8A04710096BF64 /* Release */ = { 390 | isa = XCBuildConfiguration; 391 | baseConfigurationReference = 0BFEAE319F2581E8B5EDD30B /* Pods-ImageScrollViewDemo.release.xcconfig */; 392 | buildSettings = { 393 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 394 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 395 | INFOPLIST_FILE = ImageScrollViewDemo/Info.plist; 396 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 397 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 398 | PRODUCT_BUNDLE_IDENTIFIER = com.nch.ImageScrollViewDemo; 399 | PRODUCT_NAME = "$(TARGET_NAME)"; 400 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 401 | SWIFT_VERSION = 5.0; 402 | }; 403 | name = Release; 404 | }; 405 | /* End XCBuildConfiguration section */ 406 | 407 | /* Begin XCConfigurationList section */ 408 | 61F3137A1C8A04710096BF64 /* Build configuration list for PBXProject "ImageScrollViewDemo" */ = { 409 | isa = XCConfigurationList; 410 | buildConfigurations = ( 411 | 61F3138F1C8A04710096BF64 /* Debug */, 412 | 61F313901C8A04710096BF64 /* Release */, 413 | ); 414 | defaultConfigurationIsVisible = 0; 415 | defaultConfigurationName = Release; 416 | }; 417 | 61F313911C8A04710096BF64 /* Build configuration list for PBXNativeTarget "ImageScrollViewDemo" */ = { 418 | isa = XCConfigurationList; 419 | buildConfigurations = ( 420 | 61F313921C8A04710096BF64 /* Debug */, 421 | 61F313931C8A04710096BF64 /* Release */, 422 | ); 423 | defaultConfigurationIsVisible = 0; 424 | defaultConfigurationName = Release; 425 | }; 426 | /* End XCConfigurationList section */ 427 | }; 428 | rootObject = 61F313771C8A04710096BF64 /* Project object */; 429 | } 430 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ImageScrollViewDemo 4 | // 5 | // Created by Nguyen Cong Huy on 3/5/16. 6 | // Copyright © 2016 Nguyen Cong Huy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 32 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huynguyencong/ImageScrollView/3b5bf7e1bf719facb736e43bda9403c0c661fae6/ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-0.jpg -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huynguyencong/ImageScrollView/3b5bf7e1bf719facb736e43bda9403c0c661fae6/ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-1.jpg -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huynguyencong/ImageScrollView/3b5bf7e1bf719facb736e43bda9403c0c661fae6/ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-2.jpg -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huynguyencong/ImageScrollView/3b5bf7e1bf719facb736e43bda9403c0c661fae6/ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-3.jpg -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huynguyencong/ImageScrollView/3b5bf7e1bf719facb736e43bda9403c0c661fae6/ImageScrollViewDemo/ImageScrollViewDemo/Images/dog-4.jpg -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/ImageScrollViewDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ImageScrollViewDemo 4 | // 5 | // Created by Nguyen Cong Huy on 3/5/16. 6 | // Copyright © 2016 Nguyen Cong Huy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ImageScrollView 11 | 12 | class ViewController: UIViewController { 13 | 14 | @IBOutlet weak var imageScrollView: ImageScrollView! 15 | var images = [UIImage]() 16 | var index = 0 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | 21 | for i in 0..<5 { 22 | if let image = UIImage(named: "dog-\(i).jpg") { 23 | images.append(image) 24 | } 25 | } 26 | 27 | imageScrollView.setup() 28 | imageScrollView.imageScrollViewDelegate = self 29 | imageScrollView.imageContentMode = .aspectFit 30 | imageScrollView.initialOffset = .center 31 | imageScrollView.display(image: images[index]) 32 | } 33 | 34 | @IBAction func previousButtonTap(_ sender: AnyObject) { 35 | index = (index - 1 + images.count)%images.count 36 | imageScrollView.display(image: images[index]) 37 | } 38 | 39 | @IBAction func nextButtonTap(_ sender: AnyObject) { 40 | index = (index + 1)%images.count 41 | imageScrollView.display(image: images[index]) 42 | } 43 | 44 | } 45 | 46 | extension ViewController: ImageScrollViewDelegate { 47 | func imageScrollViewDidChangeOrientation(imageScrollView: ImageScrollView) { 48 | print("Did change orientation") 49 | } 50 | 51 | func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) { 52 | print("scrollViewDidEndZooming at scale \(scale)") 53 | } 54 | 55 | func scrollViewDidScroll(_ scrollView: UIScrollView) { 56 | print("scrollViewDidScroll at offset \(scrollView.contentOffset)") 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '8.0' 2 | use_frameworks! 3 | 4 | target 'ImageScrollViewDemo' do 5 | pod 'ImageScrollView', :path => '../' 6 | end 7 | -------------------------------------------------------------------------------- /ImageScrollViewDemo/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - ImageScrollView (1.8) 3 | 4 | DEPENDENCIES: 5 | - ImageScrollView (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | ImageScrollView: 9 | :path: "../" 10 | 11 | SPEC CHECKSUMS: 12 | ImageScrollView: 82912273486297285682bdb2a806742f0d39940c 13 | 14 | PODFILE CHECKSUM: 8e836f7f52da4ac0f2f533b10582a69d9a3de51b 15 | 16 | COCOAPODS: 1.6.1 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Huy Nguyen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.2 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "ImageScrollView", 8 | products: [ 9 | // Products define the executables and libraries produced by a package, and make them visible to other packages. 10 | .library( 11 | name: "ImageScrollView", 12 | targets: ["ImageScrollView"]), 13 | ], 14 | dependencies: [ 15 | // Dependencies declare other packages that this package depends on. 16 | // .package(url: /* package url */, from: "1.0.0"), 17 | ], 18 | targets: [ 19 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 20 | // Targets can depend on other targets in this package, and on products in packages which this package depends on. 21 | .target( 22 | name: "ImageScrollView", 23 | path: "Sources"), 24 | ] 25 | ) 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ImageScrollView 2 | 3 | This is a control that will help you to display an image, with zoomable and scrollable features easily. 4 | 5 | ### About 6 | When you make an application, which has a photo viewer feature, the photo viewer usually needs to have zoomable and scrollable features, that allows your user viewing photo more details. 7 | This control will help you to display images, with zoomable and scrollable features easily. 8 | 9 | ![Demo](ReadMeImages/demo.gif) 10 | 11 | #### Compatible 12 | 13 | - iOS 9 and later. 14 | - Swift 5.0 and later (for earlier Swift version, please use earlier ImageScrollView version). 15 | 16 | ### Usage 17 | 18 | #### Cocoapod 19 | Add below line to your Podfile: 20 | 21 | ``` 22 | pod 'ImageScrollView' 23 | ``` 24 | 25 | then run below command in Terminal to install: 26 | 27 | `pod install` 28 | 29 | Note: If the above pod doesn't work, try using below pod definition in Podfile: 30 | 31 | `pod 'ImageScrollView', :git => 'https://github.com/huynguyencong/ImageScrollView.git'` 32 | 33 | #### Swift Package Manager 34 | 35 | In Xcode, select menu File -> Swift Packages -> Add Package Dependency. Select a target, then add this link to the input field: 36 | `https://github.com/huynguyencong/ImageScrollView.git` 37 | 38 | #### Manual 39 | Sometimes just want to install manually, just simply add the file `ImageSrollView.swift` in the folder `Sources` to your project. 40 | 41 | #### Simple to use 42 | Drag an UIScrollView to your storyboard, change Class and Module in Identity Inspector to ImageScrollView. Also, create an IBOutlet in your source file. 43 | 44 | ![How to config ImageScrollView in storyboard](ReadMeImages/storyboard-demo.jpeg?raw=true) 45 | 46 | ```swift 47 | import ImageScrollView 48 | ``` 49 | 50 | ```swift 51 | @IBOutlet weak var imageScrollView: ImageScrollView! 52 | ``` 53 | 54 | ```swift 55 | // Important: This setup method should be called once, usually in your viewDidLoad() method 56 | imageScrollView.setup() 57 | 58 | let myImage = UIImage(named: "my_image_name") 59 | imageScrollView.display(image: myImage) 60 | ``` 61 | That's all. Now try zooming and scrolling to see the result. 62 | 63 | You can set delegate to catch event. This delegate is inheritted from `UIScrollViewDelegate`. 64 | 65 | ```swift 66 | imageScrollView.imageScrollViewDelegate = self 67 | ``` 68 | 69 | ```swift 70 | extension ViewController: ImageScrollViewDelegate { 71 | func imageScrollViewDidChangeOrientation(imageScrollView: ImageScrollView) { 72 | print("Did change orientation") 73 | } 74 | 75 | func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) { 76 | print("scrollViewDidEndZooming at scale \(scale)") 77 | } 78 | 79 | func scrollViewDidScroll(_ scrollView: UIScrollView) { 80 | print("scrollViewDidScroll at offset \(scrollView.contentOffset)") 81 | } 82 | } 83 | ``` 84 | 85 | ### Note: 86 | 87 | - If you have any problem about layout, image position, make sure you have called the setup() method of the ImageScrollView. Or you can try calling the method `layoutIfNeeded()` of the view controller's view: 88 | 89 | ```swift 90 | view.layoutIfNeeded() 91 | ``` 92 | 93 | 94 | ### About this source 95 | This open source is based on PhotoScroller demo avaiable on Apple's site. The original source was written in Objective C. This open source rewrote it by using Swift, and added some new features: 96 | - Double tap to zoom. 97 | - Smoother. Fixed bug when zooming out, the control auto zooms from center, and not from the corner. 98 | 99 | ### License 100 | ImageScrollView is released under the MIT license. See LICENSE for details. Copyright © Nguyen Cong Huy 101 | -------------------------------------------------------------------------------- /ReadMeImages/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huynguyencong/ImageScrollView/3b5bf7e1bf719facb736e43bda9403c0c661fae6/ReadMeImages/demo.gif -------------------------------------------------------------------------------- /ReadMeImages/storyboard-demo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huynguyencong/ImageScrollView/3b5bf7e1bf719facb736e43bda9403c0c661fae6/ReadMeImages/storyboard-demo.jpeg -------------------------------------------------------------------------------- /Sources/ImageScrollView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ImageScrollView.swift 3 | // Beauty 4 | // 5 | // Created by Nguyen Cong Huy on 1/19/16. 6 | // Copyright © 2016 Nguyen Cong Huy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @objc public protocol ImageScrollViewDelegate: UIScrollViewDelegate { 12 | func imageScrollViewDidChangeOrientation(imageScrollView: ImageScrollView) 13 | } 14 | 15 | open class ImageScrollView: UIScrollView { 16 | 17 | @objc public enum ScaleMode: Int { 18 | case aspectFill 19 | case aspectFit 20 | case widthFill 21 | case heightFill 22 | } 23 | 24 | @objc public enum Offset: Int { 25 | case begining 26 | case center 27 | } 28 | 29 | static let kZoomInFactorFromMinWhenDoubleTap: CGFloat = 2 30 | 31 | @objc open var imageContentMode: ScaleMode = .widthFill 32 | @objc open var initialOffset: Offset = .begining 33 | 34 | @objc public private(set) var zoomView: UIImageView? = nil 35 | 36 | @objc open weak var imageScrollViewDelegate: ImageScrollViewDelegate? 37 | 38 | var imageSize: CGSize = CGSize.zero 39 | private var pointToCenterAfterResize: CGPoint = CGPoint.zero 40 | private var scaleToRestoreAfterResize: CGFloat = 1.0 41 | open var maxScaleFromMinScale: CGFloat = 3.0 42 | 43 | override open var frame: CGRect { 44 | willSet { 45 | if frame.equalTo(newValue) == false && newValue.equalTo(CGRect.zero) == false && imageSize.equalTo(CGSize.zero) == false { 46 | prepareToResize() 47 | } 48 | } 49 | 50 | didSet { 51 | if frame.equalTo(oldValue) == false && frame.equalTo(CGRect.zero) == false && imageSize.equalTo(CGSize.zero) == false { 52 | recoverFromResizing() 53 | } 54 | } 55 | } 56 | 57 | override public init(frame: CGRect) { 58 | super.init(frame: frame) 59 | 60 | initialize() 61 | } 62 | 63 | required public init?(coder aDecoder: NSCoder) { 64 | super.init(coder: aDecoder) 65 | 66 | initialize() 67 | } 68 | 69 | deinit { 70 | NotificationCenter.default.removeObserver(self) 71 | } 72 | 73 | private func initialize() { 74 | showsVerticalScrollIndicator = false 75 | showsHorizontalScrollIndicator = false 76 | bouncesZoom = true 77 | decelerationRate = UIScrollView.DecelerationRate.fast 78 | delegate = self 79 | 80 | NotificationCenter.default.addObserver(self, selector: #selector(ImageScrollView.changeOrientationNotification), name: UIDevice.orientationDidChangeNotification, object: nil) 81 | } 82 | 83 | @objc public func adjustFrameToCenter() { 84 | 85 | guard let unwrappedZoomView = zoomView else { 86 | return 87 | } 88 | 89 | var frameToCenter = unwrappedZoomView.frame 90 | 91 | // center horizontally 92 | if frameToCenter.size.width < bounds.width { 93 | frameToCenter.origin.x = (bounds.width - frameToCenter.size.width) / 2 94 | } 95 | else { 96 | frameToCenter.origin.x = 0 97 | } 98 | 99 | // center vertically 100 | if frameToCenter.size.height < bounds.height { 101 | frameToCenter.origin.y = (bounds.height - frameToCenter.size.height) / 2 102 | } 103 | else { 104 | frameToCenter.origin.y = 0 105 | } 106 | 107 | unwrappedZoomView.frame = frameToCenter 108 | } 109 | 110 | private func prepareToResize() { 111 | let boundsCenter = CGPoint(x: bounds.midX, y: bounds.midY) 112 | pointToCenterAfterResize = convert(boundsCenter, to: zoomView) 113 | 114 | scaleToRestoreAfterResize = zoomScale 115 | 116 | // If we're at the minimum zoom scale, preserve that by returning 0, which will be converted to the minimum 117 | // allowable scale when the scale is restored. 118 | if scaleToRestoreAfterResize <= minimumZoomScale + CGFloat(Float.ulpOfOne) { 119 | scaleToRestoreAfterResize = 0 120 | } 121 | } 122 | 123 | private func recoverFromResizing() { 124 | setMaxMinZoomScalesForCurrentBounds() 125 | 126 | // restore zoom scale, first making sure it is within the allowable range. 127 | let maxZoomScale = max(minimumZoomScale, scaleToRestoreAfterResize) 128 | zoomScale = min(maximumZoomScale, maxZoomScale) 129 | 130 | // restore center point, first making sure it is within the allowable range. 131 | 132 | // convert our desired center point back to our own coordinate space 133 | let boundsCenter = convert(pointToCenterAfterResize, to: zoomView) 134 | 135 | // calculate the content offset that would yield that center point 136 | var offset = CGPoint(x: boundsCenter.x - bounds.size.width/2.0, y: boundsCenter.y - bounds.size.height/2.0) 137 | 138 | // restore offset, adjusted to be within the allowable range 139 | let maxOffset = maximumContentOffset() 140 | let minOffset = minimumContentOffset() 141 | 142 | var realMaxOffset = min(maxOffset.x, offset.x) 143 | offset.x = max(minOffset.x, realMaxOffset) 144 | 145 | realMaxOffset = min(maxOffset.y, offset.y) 146 | offset.y = max(minOffset.y, realMaxOffset) 147 | 148 | contentOffset = offset 149 | } 150 | 151 | private func maximumContentOffset() -> CGPoint { 152 | return CGPoint(x: contentSize.width - bounds.width,y:contentSize.height - bounds.height) 153 | } 154 | 155 | private func minimumContentOffset() -> CGPoint { 156 | return CGPoint.zero 157 | } 158 | 159 | // MARK: - Set up 160 | 161 | open func setup() { 162 | var topSupperView = superview 163 | 164 | while topSupperView?.superview != nil { 165 | topSupperView = topSupperView?.superview 166 | } 167 | 168 | // Make sure views have already layout with precise frame 169 | topSupperView?.layoutIfNeeded() 170 | 171 | DispatchQueue.main.async { 172 | self.refresh() 173 | } 174 | } 175 | 176 | // MARK: - Display image 177 | 178 | @objc open func display(image: UIImage) { 179 | 180 | if let zoomView = zoomView { 181 | zoomView.removeFromSuperview() 182 | } 183 | 184 | zoomView = UIImageView(image: image) 185 | zoomView!.isUserInteractionEnabled = true 186 | addSubview(zoomView!) 187 | 188 | let tapGesture = UITapGestureRecognizer(target: self, action: #selector(ImageScrollView.doubleTapGestureRecognizer(_:))) 189 | tapGesture.numberOfTapsRequired = 2 190 | zoomView!.addGestureRecognizer(tapGesture) 191 | 192 | configureImageForSize(image.size) 193 | } 194 | 195 | private func configureImageForSize(_ size: CGSize) { 196 | imageSize = size 197 | contentSize = imageSize 198 | setMaxMinZoomScalesForCurrentBounds() 199 | zoomScale = minimumZoomScale 200 | 201 | switch initialOffset { 202 | case .begining: 203 | contentOffset = CGPoint.zero 204 | case .center: 205 | let xOffset = contentSize.width < bounds.width ? 0 : (contentSize.width - bounds.width)/2 206 | let yOffset = contentSize.height < bounds.height ? 0 : (contentSize.height - bounds.height)/2 207 | 208 | switch imageContentMode { 209 | case .aspectFit: 210 | contentOffset = CGPoint.zero 211 | case .aspectFill: 212 | contentOffset = CGPoint(x: xOffset, y: yOffset) 213 | case .heightFill: 214 | contentOffset = CGPoint(x: xOffset, y: 0) 215 | case .widthFill: 216 | contentOffset = CGPoint(x: 0, y: yOffset) 217 | } 218 | } 219 | } 220 | 221 | private func setMaxMinZoomScalesForCurrentBounds() { 222 | // calculate min/max zoomscale 223 | let xScale = bounds.width / imageSize.width // the scale needed to perfectly fit the image width-wise 224 | let yScale = bounds.height / imageSize.height // the scale needed to perfectly fit the image height-wise 225 | 226 | var minScale: CGFloat = 1 227 | 228 | switch imageContentMode { 229 | case .aspectFill: 230 | minScale = max(xScale, yScale) 231 | case .aspectFit: 232 | minScale = min(xScale, yScale) 233 | case .widthFill: 234 | minScale = xScale 235 | case .heightFill: 236 | minScale = yScale 237 | } 238 | 239 | 240 | let maxScale = maxScaleFromMinScale*minScale 241 | 242 | // don't let minScale exceed maxScale. (If the image is smaller than the screen, we don't want to force it to be zoomed.) 243 | if minScale > maxScale { 244 | minScale = maxScale 245 | } 246 | 247 | maximumZoomScale = maxScale 248 | minimumZoomScale = minScale * 0.999 // the multiply factor to prevent user cannot scroll page while they use this control in UIPageViewController 249 | } 250 | 251 | // MARK: - Gesture 252 | 253 | @objc func doubleTapGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer) { 254 | // zoom out if it bigger than the scale factor after double-tap scaling. Else, zoom in 255 | if zoomScale >= minimumZoomScale * ImageScrollView.kZoomInFactorFromMinWhenDoubleTap - 0.01 { 256 | setZoomScale(minimumZoomScale, animated: true) 257 | } else { 258 | let center = gestureRecognizer.location(in: gestureRecognizer.view) 259 | let zoomRect = zoomRectForScale(ImageScrollView.kZoomInFactorFromMinWhenDoubleTap * minimumZoomScale, center: center) 260 | zoom(to: zoomRect, animated: true) 261 | } 262 | } 263 | 264 | private func zoomRectForScale(_ scale: CGFloat, center: CGPoint) -> CGRect { 265 | var zoomRect = CGRect.zero 266 | 267 | // the zoom rect is in the content view's coordinates. 268 | // at a zoom scale of 1.0, it would be the size of the imageScrollView's bounds. 269 | // as the zoom scale decreases, so more content is visible, the size of the rect grows. 270 | zoomRect.size.height = frame.size.height / scale 271 | zoomRect.size.width = frame.size.width / scale 272 | 273 | // choose an origin so as to get the right center. 274 | zoomRect.origin.x = center.x - (zoomRect.size.width / 2.0) 275 | zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0) 276 | 277 | return zoomRect 278 | } 279 | 280 | open func refresh() { 281 | if let image = zoomView?.image { 282 | display(image: image) 283 | } 284 | } 285 | 286 | // MARK: - Actions 287 | 288 | @objc func changeOrientationNotification() { 289 | // A weird bug that frames are not update right after orientation changed. Need delay a little bit with async. 290 | DispatchQueue.main.async { 291 | self.configureImageForSize(self.imageSize) 292 | self.imageScrollViewDelegate?.imageScrollViewDidChangeOrientation(imageScrollView: self) 293 | } 294 | } 295 | } 296 | 297 | extension ImageScrollView: UIScrollViewDelegate { 298 | 299 | public func scrollViewDidScroll(_ scrollView: UIScrollView) { 300 | imageScrollViewDelegate?.scrollViewDidScroll?(scrollView) 301 | } 302 | 303 | public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { 304 | imageScrollViewDelegate?.scrollViewWillBeginDragging?(scrollView) 305 | } 306 | 307 | public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { 308 | imageScrollViewDelegate?.scrollViewWillEndDragging?(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset) 309 | } 310 | 311 | public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { 312 | imageScrollViewDelegate?.scrollViewDidEndDragging?(scrollView, willDecelerate: decelerate) 313 | } 314 | 315 | public func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) { 316 | imageScrollViewDelegate?.scrollViewWillBeginDecelerating?(scrollView) 317 | } 318 | 319 | public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { 320 | imageScrollViewDelegate?.scrollViewDidEndDecelerating?(scrollView) 321 | } 322 | 323 | public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) { 324 | imageScrollViewDelegate?.scrollViewDidEndScrollingAnimation?(scrollView) 325 | } 326 | 327 | public func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) { 328 | imageScrollViewDelegate?.scrollViewWillBeginZooming?(scrollView, with: view) 329 | } 330 | 331 | public func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) { 332 | imageScrollViewDelegate?.scrollViewDidEndZooming?(scrollView, with: view, atScale: scale) 333 | } 334 | 335 | public func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool { 336 | return false 337 | } 338 | 339 | @available(iOS 11.0, *) 340 | public func scrollViewDidChangeAdjustedContentInset(_ scrollView: UIScrollView) { 341 | imageScrollViewDelegate?.scrollViewDidChangeAdjustedContentInset?(scrollView) 342 | } 343 | 344 | public func viewForZooming(in scrollView: UIScrollView) -> UIView? { 345 | return zoomView 346 | } 347 | 348 | public func scrollViewDidZoom(_ scrollView: UIScrollView) { 349 | adjustFrameToCenter() 350 | imageScrollViewDelegate?.scrollViewDidZoom?(scrollView) 351 | } 352 | 353 | } 354 | --------------------------------------------------------------------------------