├── .gitignore ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── Example │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── cat.imageset │ │ ├── Contents.json │ │ └── zeke-tucker-gSSK4u8yPpM-unsplash.jpg │ └── dog.imageset │ │ ├── Contents.json │ │ └── dieny-portinanni-5QcwI4oxL6g-unsplash.jpg │ ├── ContentView.swift │ ├── ExampleApp.swift │ └── Preview Content │ └── Preview Assets.xcassets │ └── Contents.json ├── LICENSE ├── Package.swift ├── README.md ├── Sources └── Zoomable │ └── Zoomable.swift └── Tests └── ZoomableTests └── ZoomableTests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | xcuserdata/ 5 | DerivedData/ 6 | .swiftpm/configuration/registries.json 7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 8 | .netrc 9 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 60; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D97D07DA2AD385F3005DD6FB /* ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D97D07D92AD385F3005DD6FB /* ExampleApp.swift */; }; 11 | D97D07DC2AD385F3005DD6FB /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D97D07DB2AD385F3005DD6FB /* ContentView.swift */; }; 12 | D97D07DE2AD385F4005DD6FB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D97D07DD2AD385F4005DD6FB /* Assets.xcassets */; }; 13 | D97D07E12AD385F4005DD6FB /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D97D07E02AD385F4005DD6FB /* Preview Assets.xcassets */; }; 14 | D97D07E92AD3860A005DD6FB /* Zoomable in Frameworks */ = {isa = PBXBuildFile; productRef = D97D07E82AD3860A005DD6FB /* Zoomable */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | D97D07D62AD385F3005DD6FB /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | D97D07D92AD385F3005DD6FB /* ExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleApp.swift; sourceTree = ""; }; 20 | D97D07DB2AD385F3005DD6FB /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 21 | D97D07DD2AD385F4005DD6FB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 22 | D97D07E02AD385F4005DD6FB /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 23 | /* End PBXFileReference section */ 24 | 25 | /* Begin PBXFrameworksBuildPhase section */ 26 | D97D07D32AD385F3005DD6FB /* Frameworks */ = { 27 | isa = PBXFrameworksBuildPhase; 28 | buildActionMask = 2147483647; 29 | files = ( 30 | D97D07E92AD3860A005DD6FB /* Zoomable in Frameworks */, 31 | ); 32 | runOnlyForDeploymentPostprocessing = 0; 33 | }; 34 | /* End PBXFrameworksBuildPhase section */ 35 | 36 | /* Begin PBXGroup section */ 37 | D97D07CD2AD385F3005DD6FB = { 38 | isa = PBXGroup; 39 | children = ( 40 | D97D07D82AD385F3005DD6FB /* Example */, 41 | D97D07D72AD385F3005DD6FB /* Products */, 42 | ); 43 | sourceTree = ""; 44 | }; 45 | D97D07D72AD385F3005DD6FB /* Products */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | D97D07D62AD385F3005DD6FB /* Example.app */, 49 | ); 50 | name = Products; 51 | sourceTree = ""; 52 | }; 53 | D97D07D82AD385F3005DD6FB /* Example */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | D97D07D92AD385F3005DD6FB /* ExampleApp.swift */, 57 | D97D07DB2AD385F3005DD6FB /* ContentView.swift */, 58 | D97D07DD2AD385F4005DD6FB /* Assets.xcassets */, 59 | D97D07DF2AD385F4005DD6FB /* Preview Content */, 60 | ); 61 | path = Example; 62 | sourceTree = ""; 63 | }; 64 | D97D07DF2AD385F4005DD6FB /* Preview Content */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | D97D07E02AD385F4005DD6FB /* Preview Assets.xcassets */, 68 | ); 69 | path = "Preview Content"; 70 | sourceTree = ""; 71 | }; 72 | /* End PBXGroup section */ 73 | 74 | /* Begin PBXNativeTarget section */ 75 | D97D07D52AD385F3005DD6FB /* Example */ = { 76 | isa = PBXNativeTarget; 77 | buildConfigurationList = D97D07E42AD385F4005DD6FB /* Build configuration list for PBXNativeTarget "Example" */; 78 | buildPhases = ( 79 | D97D07D22AD385F3005DD6FB /* Sources */, 80 | D97D07D32AD385F3005DD6FB /* Frameworks */, 81 | D97D07D42AD385F3005DD6FB /* Resources */, 82 | ); 83 | buildRules = ( 84 | ); 85 | dependencies = ( 86 | ); 87 | name = Example; 88 | packageProductDependencies = ( 89 | D97D07E82AD3860A005DD6FB /* Zoomable */, 90 | ); 91 | productName = Example; 92 | productReference = D97D07D62AD385F3005DD6FB /* Example.app */; 93 | productType = "com.apple.product-type.application"; 94 | }; 95 | /* End PBXNativeTarget section */ 96 | 97 | /* Begin PBXProject section */ 98 | D97D07CE2AD385F3005DD6FB /* Project object */ = { 99 | isa = PBXProject; 100 | attributes = { 101 | BuildIndependentTargetsInParallel = 1; 102 | LastSwiftUpdateCheck = 1500; 103 | LastUpgradeCheck = 1500; 104 | TargetAttributes = { 105 | D97D07D52AD385F3005DD6FB = { 106 | CreatedOnToolsVersion = 15.0; 107 | }; 108 | }; 109 | }; 110 | buildConfigurationList = D97D07D12AD385F3005DD6FB /* Build configuration list for PBXProject "Example" */; 111 | compatibilityVersion = "Xcode 14.0"; 112 | developmentRegion = en; 113 | hasScannedForEncodings = 0; 114 | knownRegions = ( 115 | en, 116 | Base, 117 | ); 118 | mainGroup = D97D07CD2AD385F3005DD6FB; 119 | packageReferences = ( 120 | D97D07E72AD3860A005DD6FB /* XCLocalSwiftPackageReference ".." */, 121 | ); 122 | productRefGroup = D97D07D72AD385F3005DD6FB /* Products */; 123 | projectDirPath = ""; 124 | projectRoot = ""; 125 | targets = ( 126 | D97D07D52AD385F3005DD6FB /* Example */, 127 | ); 128 | }; 129 | /* End PBXProject section */ 130 | 131 | /* Begin PBXResourcesBuildPhase section */ 132 | D97D07D42AD385F3005DD6FB /* Resources */ = { 133 | isa = PBXResourcesBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | D97D07E12AD385F4005DD6FB /* Preview Assets.xcassets in Resources */, 137 | D97D07DE2AD385F4005DD6FB /* Assets.xcassets in Resources */, 138 | ); 139 | runOnlyForDeploymentPostprocessing = 0; 140 | }; 141 | /* End PBXResourcesBuildPhase section */ 142 | 143 | /* Begin PBXSourcesBuildPhase section */ 144 | D97D07D22AD385F3005DD6FB /* Sources */ = { 145 | isa = PBXSourcesBuildPhase; 146 | buildActionMask = 2147483647; 147 | files = ( 148 | D97D07DC2AD385F3005DD6FB /* ContentView.swift in Sources */, 149 | D97D07DA2AD385F3005DD6FB /* ExampleApp.swift in Sources */, 150 | ); 151 | runOnlyForDeploymentPostprocessing = 0; 152 | }; 153 | /* End PBXSourcesBuildPhase section */ 154 | 155 | /* Begin XCBuildConfiguration section */ 156 | D97D07E22AD385F4005DD6FB /* Debug */ = { 157 | isa = XCBuildConfiguration; 158 | buildSettings = { 159 | ALWAYS_SEARCH_USER_PATHS = NO; 160 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 161 | CLANG_ANALYZER_NONNULL = YES; 162 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 163 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 164 | CLANG_ENABLE_MODULES = YES; 165 | CLANG_ENABLE_OBJC_ARC = YES; 166 | CLANG_ENABLE_OBJC_WEAK = YES; 167 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 168 | CLANG_WARN_BOOL_CONVERSION = YES; 169 | CLANG_WARN_COMMA = YES; 170 | CLANG_WARN_CONSTANT_CONVERSION = YES; 171 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 172 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 173 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 174 | CLANG_WARN_EMPTY_BODY = YES; 175 | CLANG_WARN_ENUM_CONVERSION = YES; 176 | CLANG_WARN_INFINITE_RECURSION = YES; 177 | CLANG_WARN_INT_CONVERSION = YES; 178 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 179 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 180 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 181 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 182 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 183 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 184 | CLANG_WARN_STRICT_PROTOTYPES = YES; 185 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 186 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 187 | CLANG_WARN_UNREACHABLE_CODE = YES; 188 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 189 | COPY_PHASE_STRIP = NO; 190 | DEBUG_INFORMATION_FORMAT = dwarf; 191 | ENABLE_STRICT_OBJC_MSGSEND = YES; 192 | ENABLE_TESTABILITY = YES; 193 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 194 | GCC_C_LANGUAGE_STANDARD = gnu17; 195 | GCC_DYNAMIC_NO_PIC = NO; 196 | GCC_NO_COMMON_BLOCKS = YES; 197 | GCC_OPTIMIZATION_LEVEL = 0; 198 | GCC_PREPROCESSOR_DEFINITIONS = ( 199 | "DEBUG=1", 200 | "$(inherited)", 201 | ); 202 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 203 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 204 | GCC_WARN_UNDECLARED_SELECTOR = YES; 205 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 206 | GCC_WARN_UNUSED_FUNCTION = YES; 207 | GCC_WARN_UNUSED_VARIABLE = YES; 208 | IPHONEOS_DEPLOYMENT_TARGET = 17.0; 209 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 210 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 211 | MTL_FAST_MATH = YES; 212 | ONLY_ACTIVE_ARCH = YES; 213 | SDKROOT = iphoneos; 214 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; 215 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 216 | }; 217 | name = Debug; 218 | }; 219 | D97D07E32AD385F4005DD6FB /* Release */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | ALWAYS_SEARCH_USER_PATHS = NO; 223 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 224 | CLANG_ANALYZER_NONNULL = YES; 225 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 226 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 227 | CLANG_ENABLE_MODULES = YES; 228 | CLANG_ENABLE_OBJC_ARC = YES; 229 | CLANG_ENABLE_OBJC_WEAK = YES; 230 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 231 | CLANG_WARN_BOOL_CONVERSION = YES; 232 | CLANG_WARN_COMMA = YES; 233 | CLANG_WARN_CONSTANT_CONVERSION = YES; 234 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 235 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 236 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 237 | CLANG_WARN_EMPTY_BODY = YES; 238 | CLANG_WARN_ENUM_CONVERSION = YES; 239 | CLANG_WARN_INFINITE_RECURSION = YES; 240 | CLANG_WARN_INT_CONVERSION = YES; 241 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 242 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 243 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 244 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 245 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 246 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 247 | CLANG_WARN_STRICT_PROTOTYPES = YES; 248 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 249 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 250 | CLANG_WARN_UNREACHABLE_CODE = YES; 251 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 252 | COPY_PHASE_STRIP = NO; 253 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 254 | ENABLE_NS_ASSERTIONS = NO; 255 | ENABLE_STRICT_OBJC_MSGSEND = YES; 256 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 257 | GCC_C_LANGUAGE_STANDARD = gnu17; 258 | GCC_NO_COMMON_BLOCKS = YES; 259 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 260 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 261 | GCC_WARN_UNDECLARED_SELECTOR = YES; 262 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 263 | GCC_WARN_UNUSED_FUNCTION = YES; 264 | GCC_WARN_UNUSED_VARIABLE = YES; 265 | IPHONEOS_DEPLOYMENT_TARGET = 17.0; 266 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 267 | MTL_ENABLE_DEBUG_INFO = NO; 268 | MTL_FAST_MATH = YES; 269 | SDKROOT = iphoneos; 270 | SWIFT_COMPILATION_MODE = wholemodule; 271 | VALIDATE_PRODUCT = YES; 272 | }; 273 | name = Release; 274 | }; 275 | D97D07E52AD385F4005DD6FB /* Debug */ = { 276 | isa = XCBuildConfiguration; 277 | buildSettings = { 278 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 279 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 280 | CODE_SIGN_STYLE = Automatic; 281 | CURRENT_PROJECT_VERSION = 1; 282 | DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\""; 283 | DEVELOPMENT_TEAM = YY246BG4R2; 284 | ENABLE_PREVIEWS = YES; 285 | GENERATE_INFOPLIST_FILE = YES; 286 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 287 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 288 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 289 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 290 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 291 | LD_RUNPATH_SEARCH_PATHS = ( 292 | "$(inherited)", 293 | "@executable_path/Frameworks", 294 | ); 295 | MARKETING_VERSION = 1.0; 296 | PRODUCT_BUNDLE_IDENTIFIER = jp.codingcafe.Example; 297 | PRODUCT_NAME = "$(TARGET_NAME)"; 298 | SWIFT_EMIT_LOC_STRINGS = YES; 299 | SWIFT_VERSION = 5.0; 300 | TARGETED_DEVICE_FAMILY = "1,2"; 301 | }; 302 | name = Debug; 303 | }; 304 | D97D07E62AD385F4005DD6FB /* Release */ = { 305 | isa = XCBuildConfiguration; 306 | buildSettings = { 307 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 308 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 309 | CODE_SIGN_STYLE = Automatic; 310 | CURRENT_PROJECT_VERSION = 1; 311 | DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\""; 312 | DEVELOPMENT_TEAM = YY246BG4R2; 313 | ENABLE_PREVIEWS = YES; 314 | GENERATE_INFOPLIST_FILE = YES; 315 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 316 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 317 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 318 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 319 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 320 | LD_RUNPATH_SEARCH_PATHS = ( 321 | "$(inherited)", 322 | "@executable_path/Frameworks", 323 | ); 324 | MARKETING_VERSION = 1.0; 325 | PRODUCT_BUNDLE_IDENTIFIER = jp.codingcafe.Example; 326 | PRODUCT_NAME = "$(TARGET_NAME)"; 327 | SWIFT_EMIT_LOC_STRINGS = YES; 328 | SWIFT_VERSION = 5.0; 329 | TARGETED_DEVICE_FAMILY = "1,2"; 330 | }; 331 | name = Release; 332 | }; 333 | /* End XCBuildConfiguration section */ 334 | 335 | /* Begin XCConfigurationList section */ 336 | D97D07D12AD385F3005DD6FB /* Build configuration list for PBXProject "Example" */ = { 337 | isa = XCConfigurationList; 338 | buildConfigurations = ( 339 | D97D07E22AD385F4005DD6FB /* Debug */, 340 | D97D07E32AD385F4005DD6FB /* Release */, 341 | ); 342 | defaultConfigurationIsVisible = 0; 343 | defaultConfigurationName = Release; 344 | }; 345 | D97D07E42AD385F4005DD6FB /* Build configuration list for PBXNativeTarget "Example" */ = { 346 | isa = XCConfigurationList; 347 | buildConfigurations = ( 348 | D97D07E52AD385F4005DD6FB /* Debug */, 349 | D97D07E62AD385F4005DD6FB /* Release */, 350 | ); 351 | defaultConfigurationIsVisible = 0; 352 | defaultConfigurationName = Release; 353 | }; 354 | /* End XCConfigurationList section */ 355 | 356 | /* Begin XCLocalSwiftPackageReference section */ 357 | D97D07E72AD3860A005DD6FB /* XCLocalSwiftPackageReference ".." */ = { 358 | isa = XCLocalSwiftPackageReference; 359 | relativePath = ..; 360 | }; 361 | /* End XCLocalSwiftPackageReference section */ 362 | 363 | /* Begin XCSwiftPackageProductDependency section */ 364 | D97D07E82AD3860A005DD6FB /* Zoomable */ = { 365 | isa = XCSwiftPackageProductDependency; 366 | productName = Zoomable; 367 | }; 368 | /* End XCSwiftPackageProductDependency section */ 369 | }; 370 | rootObject = D97D07CE2AD385F3005DD6FB /* Project object */; 371 | } 372 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "platform" : "ios", 6 | "size" : "1024x1024" 7 | } 8 | ], 9 | "info" : { 10 | "author" : "xcode", 11 | "version" : 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/cat.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "zeke-tucker-gSSK4u8yPpM-unsplash.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/cat.imageset/zeke-tucker-gSSK4u8yPpM-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ryohey/Zoomable/525c0e1784825261b84d21c5cd5a159245a40ea6/Example/Example/Assets.xcassets/cat.imageset/zeke-tucker-gSSK4u8yPpM-unsplash.jpg -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/dog.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "dieny-portinanni-5QcwI4oxL6g-unsplash.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/dog.imageset/dieny-portinanni-5QcwI4oxL6g-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ryohey/Zoomable/525c0e1784825261b84d21c5cd5a159245a40ea6/Example/Example/Assets.xcassets/dog.imageset/dieny-portinanni-5QcwI4oxL6g-unsplash.jpg -------------------------------------------------------------------------------- /Example/Example/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // Example 4 | // 5 | // Created by Ryohei Kameyama on 2023/10/09. 6 | // 7 | 8 | import SwiftUI 9 | import Zoomable 10 | 11 | struct ContentView: View { 12 | var body: some View { 13 | Image(.dog) 14 | .scaledToFit() 15 | .zoomable() 16 | } 17 | } 18 | 19 | #Preview { 20 | ContentView() 21 | } 22 | -------------------------------------------------------------------------------- /Example/Example/ExampleApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleApp.swift 3 | // Example 4 | // 5 | // Created by Ryohei Kameyama on 2023/10/09. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct ExampleApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Example/Example/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 ryohey 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.9 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: "Zoomable", 8 | platforms: [ 9 | .iOS(.v16), 10 | ], 11 | products: [ 12 | // Products define the executables and libraries a package produces, making them visible to other packages. 13 | .library( 14 | name: "Zoomable", 15 | targets: ["Zoomable"]), 16 | ], 17 | targets: [ 18 | // Targets are the basic building blocks of a package, defining a module or a test suite. 19 | // Targets can depend on other targets in this package and products from dependencies. 20 | .target( 21 | name: "Zoomable"), 22 | .testTarget( 23 | name: "ZoomableTests", 24 | dependencies: ["Zoomable"]), 25 | ] 26 | ) 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zoomable 2 | 3 | A SwiftUI view modifier that provides pinch to zoom, double tap to zoom, and drag to pan functionalities for iOS ad iPadOS apps. 4 | 5 | Supports Image and any kind of View, including `UIViewControllerRepresentable` and `UIViewRepresentable`. 6 | 7 | 8 | https://github.com/ryohey/Zoomable/assets/5355966/d88a9290-ee1d-4dd9-ac2c-b1e68548d256 9 | 10 | 11 | 12 | ## Features 13 | 14 | - Pinch to zoom 15 | - Double tap to zoom in and out 16 | - Drag to pan 17 | 18 | ## Installation 19 | 20 | ### Swift Package Manager 21 | 22 | Please add the following URL in the `Package Dependencies` screen in Xcode. 23 | 24 | ``` 25 | https://github.com/ryohey/Zoomable.git 26 | ``` 27 | 28 | ## Usage 29 | 30 | To use the `Zoomable` modifier in your SwiftUI view: 31 | 32 | ```swift 33 | import Zoomable 34 | 35 | struct ContentView: View { 36 | var body: some View { 37 | Image("your-image-name") 38 | .zoomable() 39 | 40 | /* 41 | or 42 | SomeView() 43 | .zoomable( 44 | minZoomScale: 0.5, // Default value: 1 45 | doubleTapZoomScale: 2, // Default value: 3 46 | outOfBoundsColor: .black // Default value: .clear 47 | ) 48 | */ 49 | } 50 | } 51 | ``` 52 | 53 | ## Requirements 54 | 55 | - iOS 16.0 or later 56 | - SwiftUI 57 | 58 | ## Caveats 59 | 60 | - **iOS 16**: Due to limitations with `MagnificationGesture`, during pinch-in actions, the zoom location is fixed to the top-left corner. 61 | - **iOS 17 and later**: This issue has been addressed and improved with the introduction of `MagnifyGesture`. 62 | 63 | ## Contribution 64 | 65 | Contributions are welcome! Please open an issue or submit a pull request. 66 | 67 | ## License 68 | 69 | MIT License 70 | -------------------------------------------------------------------------------- /Sources/Zoomable/Zoomable.swift: -------------------------------------------------------------------------------- 1 | #if os(iOS) 2 | 3 | import SwiftUI 4 | 5 | struct ZoomableModifier: ViewModifier { 6 | let minZoomScale: CGFloat 7 | let doubleTapZoomScale: CGFloat 8 | 9 | @State private var lastTransform: CGAffineTransform = .identity 10 | @State private var transform: CGAffineTransform = .identity 11 | @State private var contentSize: CGSize = .zero 12 | 13 | func body(content: Content) -> some View { 14 | content 15 | .background(alignment: .topLeading) { 16 | GeometryReader { proxy in 17 | Color.clear 18 | .onAppear { 19 | contentSize = proxy.size 20 | } 21 | } 22 | } 23 | .animatableTransformEffect(transform) 24 | .gesture(dragGesture, including: transform == .identity ? .none : .all) 25 | .modify { view in 26 | if #available(iOS 17.0, *) { 27 | view.gesture(magnificationGesture) 28 | } else { 29 | view.gesture(oldMagnificationGesture) 30 | } 31 | } 32 | .gesture(doubleTapGesture) 33 | } 34 | 35 | @available(iOS, introduced: 16.0, deprecated: 17.0) 36 | private var oldMagnificationGesture: some Gesture { 37 | MagnificationGesture() 38 | .onChanged { value in 39 | let zoomFactor = 0.5 40 | let scale = value * zoomFactor 41 | transform = lastTransform.scaledBy(x: scale, y: scale) 42 | } 43 | .onEnded { _ in 44 | onEndGesture() 45 | } 46 | } 47 | 48 | @available(iOS 17.0, *) 49 | private var magnificationGesture: some Gesture { 50 | MagnifyGesture(minimumScaleDelta: 0) 51 | .onChanged { value in 52 | let newTransform = CGAffineTransform.anchoredScale( 53 | scale: value.magnification, 54 | anchor: value.startAnchor.scaledBy(contentSize) 55 | ) 56 | 57 | withAnimation(.interactiveSpring) { 58 | transform = lastTransform.concatenating(newTransform) 59 | } 60 | } 61 | .onEnded { _ in 62 | onEndGesture() 63 | } 64 | } 65 | 66 | private var doubleTapGesture: some Gesture { 67 | SpatialTapGesture(count: 2) 68 | .onEnded { value in 69 | let newTransform: CGAffineTransform = 70 | if transform.isIdentity { 71 | .anchoredScale(scale: doubleTapZoomScale, anchor: value.location) 72 | } else { 73 | .identity 74 | } 75 | 76 | withAnimation(.linear(duration: 0.15)) { 77 | transform = newTransform 78 | lastTransform = newTransform 79 | } 80 | } 81 | } 82 | 83 | private var dragGesture: some Gesture { 84 | DragGesture() 85 | .onChanged { value in 86 | withAnimation(.interactiveSpring) { 87 | transform = lastTransform.translatedBy( 88 | x: value.translation.width / transform.scaleX, 89 | y: value.translation.height / transform.scaleY 90 | ) 91 | } 92 | } 93 | .onEnded { _ in 94 | onEndGesture() 95 | } 96 | } 97 | 98 | private func onEndGesture() { 99 | let newTransform = limitTransform(transform) 100 | 101 | withAnimation(.snappy(duration: 0.1)) { 102 | transform = newTransform 103 | lastTransform = newTransform 104 | } 105 | } 106 | 107 | private func limitTransform(_ transform: CGAffineTransform) -> CGAffineTransform { 108 | let scaleX = transform.scaleX 109 | let scaleY = transform.scaleY 110 | 111 | if scaleX < minZoomScale 112 | || scaleY < minZoomScale 113 | { 114 | return .identity 115 | } 116 | 117 | let maxX = contentSize.width * (scaleX - 1) 118 | let maxY = contentSize.height * (scaleY - 1) 119 | 120 | if transform.tx > 0 121 | || transform.tx < -maxX 122 | || transform.ty > 0 123 | || transform.ty < -maxY 124 | { 125 | let tx = min(max(transform.tx, -maxX), 0) 126 | let ty = min(max(transform.ty, -maxY), 0) 127 | var transform = transform 128 | transform.tx = tx 129 | transform.ty = ty 130 | return transform 131 | } 132 | 133 | return transform 134 | } 135 | } 136 | 137 | public extension View { 138 | @ViewBuilder 139 | func zoomable( 140 | minZoomScale: CGFloat = 1, 141 | doubleTapZoomScale: CGFloat = 3 142 | ) -> some View { 143 | modifier(ZoomableModifier( 144 | minZoomScale: minZoomScale, 145 | doubleTapZoomScale: doubleTapZoomScale 146 | )) 147 | } 148 | 149 | @ViewBuilder 150 | func zoomable( 151 | minZoomScale: CGFloat = 1, 152 | doubleTapZoomScale: CGFloat = 3, 153 | outOfBoundsColor: Color = .clear 154 | ) -> some View { 155 | GeometryReader { proxy in 156 | ZStack { 157 | outOfBoundsColor 158 | self.zoomable( 159 | minZoomScale: minZoomScale, 160 | doubleTapZoomScale: doubleTapZoomScale 161 | ) 162 | } 163 | } 164 | } 165 | } 166 | 167 | private extension View { 168 | @ViewBuilder 169 | func modify(@ViewBuilder _ fn: (Self) -> some View) -> some View { 170 | fn(self) 171 | } 172 | 173 | @ViewBuilder 174 | func animatableTransformEffect(_ transform: CGAffineTransform) -> some View { 175 | scaleEffect( 176 | x: transform.scaleX, 177 | y: transform.scaleY, 178 | anchor: .zero 179 | ) 180 | .offset(x: transform.tx, y: transform.ty) 181 | } 182 | } 183 | 184 | private extension UnitPoint { 185 | func scaledBy(_ size: CGSize) -> CGPoint { 186 | .init( 187 | x: x * size.width, 188 | y: y * size.height 189 | ) 190 | } 191 | } 192 | 193 | private extension CGAffineTransform { 194 | static func anchoredScale(scale: CGFloat, anchor: CGPoint) -> CGAffineTransform { 195 | CGAffineTransform(translationX: anchor.x, y: anchor.y) 196 | .scaledBy(x: scale, y: scale) 197 | .translatedBy(x: -anchor.x, y: -anchor.y) 198 | } 199 | 200 | var scaleX: CGFloat { 201 | sqrt(a * a + c * c) 202 | } 203 | 204 | var scaleY: CGFloat { 205 | sqrt(b * b + d * d) 206 | } 207 | } 208 | 209 | #endif 210 | -------------------------------------------------------------------------------- /Tests/ZoomableTests/ZoomableTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import Zoomable 3 | 4 | final class ZoomableTests: XCTestCase { 5 | func testExample() throws { 6 | // XCTest Documentation 7 | // https://developer.apple.com/documentation/xctest 8 | 9 | // Defining Test Cases and Test Methods 10 | // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods 11 | } 12 | } 13 | --------------------------------------------------------------------------------