├── .gitignore ├── DynamicGridZoom.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── alexmarchant.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── DynamicGridZoom ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── ContentView.swift ├── DynamicGridZoomApp.swift ├── GridZoomStages.swift └── Preview Content │ └── Preview Assets.xcassets │ └── Contents.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | xcuserdata 3 | -------------------------------------------------------------------------------- /DynamicGridZoom.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 56; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D44B2E7B2A2E9937007A4B05 /* DynamicGridZoomApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D44B2E7A2A2E9937007A4B05 /* DynamicGridZoomApp.swift */; }; 11 | D44B2E7D2A2E9937007A4B05 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D44B2E7C2A2E9937007A4B05 /* ContentView.swift */; }; 12 | D44B2E7F2A2E9939007A4B05 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D44B2E7E2A2E9939007A4B05 /* Assets.xcassets */; }; 13 | D44B2E822A2E9939007A4B05 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D44B2E812A2E9939007A4B05 /* Preview Assets.xcassets */; }; 14 | D4FB97CB2A31F0A600DE4F4F /* GridZoomStages.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4FB97CA2A31F0A600DE4F4F /* GridZoomStages.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | D44B2E772A2E9937007A4B05 /* DynamicGridZoom.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DynamicGridZoom.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | D44B2E7A2A2E9937007A4B05 /* DynamicGridZoomApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicGridZoomApp.swift; sourceTree = ""; }; 20 | D44B2E7C2A2E9937007A4B05 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 21 | D44B2E7E2A2E9939007A4B05 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 22 | D44B2E812A2E9939007A4B05 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 23 | D4FB97CA2A31F0A600DE4F4F /* GridZoomStages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridZoomStages.swift; sourceTree = ""; }; 24 | /* End PBXFileReference section */ 25 | 26 | /* Begin PBXFrameworksBuildPhase section */ 27 | D44B2E742A2E9937007A4B05 /* Frameworks */ = { 28 | isa = PBXFrameworksBuildPhase; 29 | buildActionMask = 2147483647; 30 | files = ( 31 | ); 32 | runOnlyForDeploymentPostprocessing = 0; 33 | }; 34 | /* End PBXFrameworksBuildPhase section */ 35 | 36 | /* Begin PBXGroup section */ 37 | D44B2E6E2A2E9937007A4B05 = { 38 | isa = PBXGroup; 39 | children = ( 40 | D44B2E792A2E9937007A4B05 /* DynamicGridZoom */, 41 | D44B2E782A2E9937007A4B05 /* Products */, 42 | ); 43 | sourceTree = ""; 44 | }; 45 | D44B2E782A2E9937007A4B05 /* Products */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | D44B2E772A2E9937007A4B05 /* DynamicGridZoom.app */, 49 | ); 50 | name = Products; 51 | sourceTree = ""; 52 | }; 53 | D44B2E792A2E9937007A4B05 /* DynamicGridZoom */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | D44B2E7A2A2E9937007A4B05 /* DynamicGridZoomApp.swift */, 57 | D44B2E7C2A2E9937007A4B05 /* ContentView.swift */, 58 | D4FB97CA2A31F0A600DE4F4F /* GridZoomStages.swift */, 59 | D44B2E7E2A2E9939007A4B05 /* Assets.xcassets */, 60 | D44B2E802A2E9939007A4B05 /* Preview Content */, 61 | ); 62 | path = DynamicGridZoom; 63 | sourceTree = ""; 64 | }; 65 | D44B2E802A2E9939007A4B05 /* Preview Content */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | D44B2E812A2E9939007A4B05 /* Preview Assets.xcassets */, 69 | ); 70 | path = "Preview Content"; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXNativeTarget section */ 76 | D44B2E762A2E9937007A4B05 /* DynamicGridZoom */ = { 77 | isa = PBXNativeTarget; 78 | buildConfigurationList = D44B2E852A2E9939007A4B05 /* Build configuration list for PBXNativeTarget "DynamicGridZoom" */; 79 | buildPhases = ( 80 | D44B2E732A2E9937007A4B05 /* Sources */, 81 | D44B2E742A2E9937007A4B05 /* Frameworks */, 82 | D44B2E752A2E9937007A4B05 /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = DynamicGridZoom; 89 | productName = DynamicGridZoom; 90 | productReference = D44B2E772A2E9937007A4B05 /* DynamicGridZoom.app */; 91 | productType = "com.apple.product-type.application"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | D44B2E6F2A2E9937007A4B05 /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | BuildIndependentTargetsInParallel = 1; 100 | LastSwiftUpdateCheck = 1430; 101 | LastUpgradeCheck = 1430; 102 | TargetAttributes = { 103 | D44B2E762A2E9937007A4B05 = { 104 | CreatedOnToolsVersion = 14.3.1; 105 | }; 106 | }; 107 | }; 108 | buildConfigurationList = D44B2E722A2E9937007A4B05 /* Build configuration list for PBXProject "DynamicGridZoom" */; 109 | compatibilityVersion = "Xcode 14.0"; 110 | developmentRegion = en; 111 | hasScannedForEncodings = 0; 112 | knownRegions = ( 113 | en, 114 | Base, 115 | ); 116 | mainGroup = D44B2E6E2A2E9937007A4B05; 117 | productRefGroup = D44B2E782A2E9937007A4B05 /* Products */; 118 | projectDirPath = ""; 119 | projectRoot = ""; 120 | targets = ( 121 | D44B2E762A2E9937007A4B05 /* DynamicGridZoom */, 122 | ); 123 | }; 124 | /* End PBXProject section */ 125 | 126 | /* Begin PBXResourcesBuildPhase section */ 127 | D44B2E752A2E9937007A4B05 /* Resources */ = { 128 | isa = PBXResourcesBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | D44B2E822A2E9939007A4B05 /* Preview Assets.xcassets in Resources */, 132 | D44B2E7F2A2E9939007A4B05 /* Assets.xcassets in Resources */, 133 | ); 134 | runOnlyForDeploymentPostprocessing = 0; 135 | }; 136 | /* End PBXResourcesBuildPhase section */ 137 | 138 | /* Begin PBXSourcesBuildPhase section */ 139 | D44B2E732A2E9937007A4B05 /* Sources */ = { 140 | isa = PBXSourcesBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | D44B2E7D2A2E9937007A4B05 /* ContentView.swift in Sources */, 144 | D44B2E7B2A2E9937007A4B05 /* DynamicGridZoomApp.swift in Sources */, 145 | D4FB97CB2A31F0A600DE4F4F /* GridZoomStages.swift in Sources */, 146 | ); 147 | runOnlyForDeploymentPostprocessing = 0; 148 | }; 149 | /* End PBXSourcesBuildPhase section */ 150 | 151 | /* Begin XCBuildConfiguration section */ 152 | D44B2E832A2E9939007A4B05 /* Debug */ = { 153 | isa = XCBuildConfiguration; 154 | buildSettings = { 155 | ALWAYS_SEARCH_USER_PATHS = NO; 156 | CLANG_ANALYZER_NONNULL = YES; 157 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 158 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 159 | CLANG_ENABLE_MODULES = YES; 160 | CLANG_ENABLE_OBJC_ARC = YES; 161 | CLANG_ENABLE_OBJC_WEAK = YES; 162 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 163 | CLANG_WARN_BOOL_CONVERSION = YES; 164 | CLANG_WARN_COMMA = YES; 165 | CLANG_WARN_CONSTANT_CONVERSION = YES; 166 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 167 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 168 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 169 | CLANG_WARN_EMPTY_BODY = YES; 170 | CLANG_WARN_ENUM_CONVERSION = YES; 171 | CLANG_WARN_INFINITE_RECURSION = YES; 172 | CLANG_WARN_INT_CONVERSION = YES; 173 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 174 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 175 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 176 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 177 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 178 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 179 | CLANG_WARN_STRICT_PROTOTYPES = YES; 180 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 181 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 182 | CLANG_WARN_UNREACHABLE_CODE = YES; 183 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 184 | COPY_PHASE_STRIP = NO; 185 | DEBUG_INFORMATION_FORMAT = dwarf; 186 | ENABLE_STRICT_OBJC_MSGSEND = YES; 187 | ENABLE_TESTABILITY = YES; 188 | GCC_C_LANGUAGE_STANDARD = gnu11; 189 | GCC_DYNAMIC_NO_PIC = NO; 190 | GCC_NO_COMMON_BLOCKS = YES; 191 | GCC_OPTIMIZATION_LEVEL = 0; 192 | GCC_PREPROCESSOR_DEFINITIONS = ( 193 | "DEBUG=1", 194 | "$(inherited)", 195 | ); 196 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 197 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 198 | GCC_WARN_UNDECLARED_SELECTOR = YES; 199 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 200 | GCC_WARN_UNUSED_FUNCTION = YES; 201 | GCC_WARN_UNUSED_VARIABLE = YES; 202 | IPHONEOS_DEPLOYMENT_TARGET = 16.4; 203 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 204 | MTL_FAST_MATH = YES; 205 | ONLY_ACTIVE_ARCH = YES; 206 | SDKROOT = iphoneos; 207 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 208 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 209 | }; 210 | name = Debug; 211 | }; 212 | D44B2E842A2E9939007A4B05 /* Release */ = { 213 | isa = XCBuildConfiguration; 214 | buildSettings = { 215 | ALWAYS_SEARCH_USER_PATHS = NO; 216 | CLANG_ANALYZER_NONNULL = YES; 217 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 218 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 219 | CLANG_ENABLE_MODULES = YES; 220 | CLANG_ENABLE_OBJC_ARC = YES; 221 | CLANG_ENABLE_OBJC_WEAK = YES; 222 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 223 | CLANG_WARN_BOOL_CONVERSION = YES; 224 | CLANG_WARN_COMMA = YES; 225 | CLANG_WARN_CONSTANT_CONVERSION = YES; 226 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 227 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 228 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 229 | CLANG_WARN_EMPTY_BODY = YES; 230 | CLANG_WARN_ENUM_CONVERSION = YES; 231 | CLANG_WARN_INFINITE_RECURSION = YES; 232 | CLANG_WARN_INT_CONVERSION = YES; 233 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 234 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 235 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 236 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 237 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 238 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 239 | CLANG_WARN_STRICT_PROTOTYPES = YES; 240 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 241 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 242 | CLANG_WARN_UNREACHABLE_CODE = YES; 243 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 244 | COPY_PHASE_STRIP = NO; 245 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 246 | ENABLE_NS_ASSERTIONS = NO; 247 | ENABLE_STRICT_OBJC_MSGSEND = YES; 248 | GCC_C_LANGUAGE_STANDARD = gnu11; 249 | GCC_NO_COMMON_BLOCKS = YES; 250 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 251 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 252 | GCC_WARN_UNDECLARED_SELECTOR = YES; 253 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 254 | GCC_WARN_UNUSED_FUNCTION = YES; 255 | GCC_WARN_UNUSED_VARIABLE = YES; 256 | IPHONEOS_DEPLOYMENT_TARGET = 16.4; 257 | MTL_ENABLE_DEBUG_INFO = NO; 258 | MTL_FAST_MATH = YES; 259 | SDKROOT = iphoneos; 260 | SWIFT_COMPILATION_MODE = wholemodule; 261 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 262 | VALIDATE_PRODUCT = YES; 263 | }; 264 | name = Release; 265 | }; 266 | D44B2E862A2E9939007A4B05 /* Debug */ = { 267 | isa = XCBuildConfiguration; 268 | buildSettings = { 269 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 270 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 271 | CODE_SIGN_STYLE = Automatic; 272 | CURRENT_PROJECT_VERSION = 1; 273 | DEVELOPMENT_ASSET_PATHS = "\"DynamicGridZoom/Preview Content\""; 274 | DEVELOPMENT_TEAM = YKFJWH4C9S; 275 | ENABLE_PREVIEWS = YES; 276 | GENERATE_INFOPLIST_FILE = YES; 277 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 278 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 279 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 280 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 281 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 282 | LD_RUNPATH_SEARCH_PATHS = ( 283 | "$(inherited)", 284 | "@executable_path/Frameworks", 285 | ); 286 | MARKETING_VERSION = 1.0; 287 | PRODUCT_BUNDLE_IDENTIFIER = Codelathe.DynamicGridZoom; 288 | PRODUCT_NAME = "$(TARGET_NAME)"; 289 | SWIFT_EMIT_LOC_STRINGS = YES; 290 | SWIFT_VERSION = 5.0; 291 | TARGETED_DEVICE_FAMILY = "1,2"; 292 | }; 293 | name = Debug; 294 | }; 295 | D44B2E872A2E9939007A4B05 /* Release */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 299 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 300 | CODE_SIGN_STYLE = Automatic; 301 | CURRENT_PROJECT_VERSION = 1; 302 | DEVELOPMENT_ASSET_PATHS = "\"DynamicGridZoom/Preview Content\""; 303 | DEVELOPMENT_TEAM = YKFJWH4C9S; 304 | ENABLE_PREVIEWS = YES; 305 | GENERATE_INFOPLIST_FILE = YES; 306 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 307 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 308 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 309 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 310 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 311 | LD_RUNPATH_SEARCH_PATHS = ( 312 | "$(inherited)", 313 | "@executable_path/Frameworks", 314 | ); 315 | MARKETING_VERSION = 1.0; 316 | PRODUCT_BUNDLE_IDENTIFIER = Codelathe.DynamicGridZoom; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SWIFT_EMIT_LOC_STRINGS = YES; 319 | SWIFT_VERSION = 5.0; 320 | TARGETED_DEVICE_FAMILY = "1,2"; 321 | }; 322 | name = Release; 323 | }; 324 | /* End XCBuildConfiguration section */ 325 | 326 | /* Begin XCConfigurationList section */ 327 | D44B2E722A2E9937007A4B05 /* Build configuration list for PBXProject "DynamicGridZoom" */ = { 328 | isa = XCConfigurationList; 329 | buildConfigurations = ( 330 | D44B2E832A2E9939007A4B05 /* Debug */, 331 | D44B2E842A2E9939007A4B05 /* Release */, 332 | ); 333 | defaultConfigurationIsVisible = 0; 334 | defaultConfigurationName = Release; 335 | }; 336 | D44B2E852A2E9939007A4B05 /* Build configuration list for PBXNativeTarget "DynamicGridZoom" */ = { 337 | isa = XCConfigurationList; 338 | buildConfigurations = ( 339 | D44B2E862A2E9939007A4B05 /* Debug */, 340 | D44B2E872A2E9939007A4B05 /* Release */, 341 | ); 342 | defaultConfigurationIsVisible = 0; 343 | defaultConfigurationName = Release; 344 | }; 345 | /* End XCConfigurationList section */ 346 | }; 347 | rootObject = D44B2E6F2A2E9937007A4B05 /* Project object */; 348 | } 349 | -------------------------------------------------------------------------------- /DynamicGridZoom.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DynamicGridZoom.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DynamicGridZoom.xcodeproj/xcuserdata/alexmarchant.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DynamicGridZoom.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /DynamicGridZoom/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 | -------------------------------------------------------------------------------- /DynamicGridZoom/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 | -------------------------------------------------------------------------------- /DynamicGridZoom/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /DynamicGridZoom/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // DynamicGridZoom 4 | // 5 | // Created by Alex Marchant on 06/06/2023. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ContentView: View { 11 | let data = (1...300).map { "\($0)" } 12 | 13 | @State var scale: CGFloat = 1.0 14 | 15 | // Multiple of how much to decrease the existing size to equal the next decreased size 16 | @State var scaleFactor: CGFloat = 1.0 17 | 18 | // Multiple of how much to increase the existing size to equal the next increased size 19 | @State var zoomFactor: CGFloat = 1.0 20 | 21 | @State var isMagnifying = false 22 | 23 | @State private var size: CGFloat = 100 24 | 25 | @State private var currentZoomStageIndex = 2 26 | @State private var previousZoomStageUpdateState: CGFloat = 0 27 | @State private var adjustedState: CGFloat = 0 28 | 29 | @State private var gridWidth: CGFloat = 0 30 | @State private var zooming: Bool = false 31 | 32 | var body: some View { 33 | 34 | let columns = [ 35 | GridItem(.adaptive(minimum: size), spacing: 2) 36 | ] 37 | 38 | return ScrollView { 39 | LazyVGrid(columns: columns, spacing: 2) { 40 | ForEach(data, id: \.self) { item in 41 | GridCell(item: item, size: size) 42 | } 43 | } 44 | .scrollDisabled(self.zooming) 45 | .scaleEffect(scale, anchor: .top) 46 | .background( 47 | GeometryReader { proxy in 48 | Color.clear 49 | .onAppear { 50 | self.gridWidth = proxy.frame(in: .local).width 51 | self.calculateZoomFactor(at: self.currentZoomStageIndex) 52 | } 53 | } 54 | ) 55 | .gesture(MagnificationGesture() 56 | .onChanged { state in 57 | 58 | // Adjust state so we are always working from 1 because we are changing layouts whilst magnifying 59 | var adjustedState = state - self.previousZoomStageUpdateState 60 | 61 | self.zooming = true 62 | 63 | // Decreasing the size 64 | if scale <= 1, 65 | adjustedState < 1 66 | { 67 | self.isMagnifying = false 68 | if self.currentZoomStageIndex > GridZoomStages.zoomStages.count - 1 69 | { 70 | if adjustedState > 0.95 71 | { 72 | self.scale = self.scaleFactor - (1 - adjustedState) 73 | } 74 | else 75 | { 76 | // If the user is at the upper limit of stages, cap the magnification 77 | adjustedState = 0.95 78 | } 79 | } 80 | else 81 | { 82 | // Minimise the size of the elements based on the number of items to show per-line 83 | let updatedSize = self.calculateUpdatedSize(index: self.currentZoomStageIndex + 1) 84 | 85 | self.previousZoomStageUpdateState = state - 1 86 | 87 | self.zoomFactor = updatedSize / self.size 88 | self.scaleFactor = self.size / updatedSize 89 | 90 | // Setting the scale to the scale factor between sizes ensures the user doesn't see a 'jump' between stages 91 | self.scale = self.scaleFactor 92 | 93 | self.size = updatedSize 94 | 95 | self.currentZoomStageIndex = self.currentZoomStageIndex + 1 96 | } 97 | } 98 | // Increasing the size 99 | else if scale >= self.zoomFactor, 100 | adjustedState > 1 101 | { 102 | self.isMagnifying = true 103 | if self.currentZoomStageIndex == 0 104 | { 105 | if adjustedState < 1.1 106 | { 107 | self.scale = 1 - (1 - adjustedState) 108 | } 109 | else 110 | { 111 | // If the user is at the lower limit of stages, cap the magnification 112 | adjustedState = 1.1 113 | } 114 | } 115 | else 116 | { 117 | self.currentZoomStageIndex = self.currentZoomStageIndex - 1 118 | self.previousZoomStageUpdateState = state - 1 119 | 120 | self.calculateZoomFactor(at: self.currentZoomStageIndex) 121 | 122 | self.scaleFactor = 1 123 | 124 | // Setting the scale 1 ensures the user doesn't see a 'jump' between zoomed stages 125 | self.scale = 1 126 | } 127 | } 128 | else 129 | { 130 | if self.isMagnifying 131 | { 132 | self.scale = 1 - (1 - adjustedState) 133 | } 134 | else 135 | { 136 | self.scale = self.scaleFactor - (1 - adjustedState) 137 | } 138 | } 139 | 140 | self.adjustedState = adjustedState 141 | } 142 | .onEnded { _ in 143 | 144 | let shouldMagnify = self.adjustedState > 1 145 | let animationDuration = 0.25 146 | 147 | withAnimation(.linear(duration: animationDuration)) 148 | { 149 | if shouldMagnify 150 | { 151 | // Continue zooming until it reaches limit for the next stage 152 | self.scale = self.zoomFactor 153 | } 154 | else 155 | { 156 | self.resetZoomVariables() 157 | } 158 | } 159 | 160 | if shouldMagnify 161 | { 162 | // Delay reset so zooming finishes and it smoothly transitions to the next zoom stage 163 | // This mimics the behaviour a user see's if they were to manually transition between stages by zooming 164 | DispatchQueue.main.asyncAfter(deadline: .now() + animationDuration) 165 | { 166 | if self.currentZoomStageIndex > 0 167 | { 168 | self.currentZoomStageIndex = self.currentZoomStageIndex - 1 169 | } 170 | 171 | self.resetZoomVariables() 172 | } 173 | } 174 | } 175 | ) 176 | } 177 | .padding(.horizontal, 2) 178 | } 179 | 180 | func resetZoomVariables() 181 | { 182 | self.calculateZoomFactor(at: self.currentZoomStageIndex) 183 | self.zooming = false 184 | self.scale = 1 185 | self.scaleFactor = 1 186 | self.previousZoomStageUpdateState = 0 187 | self.adjustedState = 0 188 | } 189 | 190 | func calculateUpdatedSize(index: Int) -> CGFloat 191 | { 192 | let zoomStages = GridZoomStages.getZoomStage(at: index) 193 | 194 | let availableSpace = self.gridWidth - (2 * CGFloat(zoomStages)) 195 | 196 | return availableSpace / CGFloat(zoomStages) 197 | } 198 | 199 | func calculateZoomFactor(at index: Int) 200 | { 201 | let currentSize = self.calculateUpdatedSize(index: index) 202 | let magnifiedSize = self.calculateUpdatedSize(index: index - 1) 203 | 204 | self.zoomFactor = magnifiedSize / currentSize 205 | 206 | self.size = currentSize 207 | } 208 | } 209 | 210 | struct GridCell: View { 211 | 212 | let item: String 213 | let size: CGFloat 214 | var body: some View { 215 | ZStack { 216 | RoundedRectangle(cornerRadius: 4) 217 | .frame(height: size) 218 | .foregroundColor(.blue) 219 | Text("\(item)") 220 | .foregroundColor(.white) 221 | } 222 | } 223 | } 224 | 225 | struct ContentView_Previews: PreviewProvider { 226 | static var previews: some View { 227 | ContentView() 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /DynamicGridZoom/DynamicGridZoomApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DynamicGridZoomApp.swift 3 | // DynamicGridZoom 4 | // 5 | // Created by Alex Marchant on 06/06/2023. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct DynamicGridZoomApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DynamicGridZoom/GridZoomStages.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GridZoomStages.swift 3 | // DynamicGridZoom 4 | // 5 | // Created by Alex Marchant on 08/06/2023. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct GridZoomStages 11 | { 12 | static var zoomStages: [Int] 13 | { 14 | if UIDevice.current.userInterfaceIdiom == .pad 15 | { 16 | if UIDevice.current.orientation.isLandscape 17 | { 18 | return [4, 6, 10, 14, 18] 19 | } 20 | else 21 | { 22 | return [4, 6, 8, 10, 12] 23 | } 24 | } 25 | else 26 | { 27 | if UIDevice.current.orientation.isLandscape 28 | { 29 | return [4, 6, 8, 9] 30 | } 31 | else 32 | { 33 | return [1, 2, 4, 6, 8] 34 | } 35 | } 36 | } 37 | 38 | static func getZoomStage(at index: Int) -> Int 39 | { 40 | if index >= zoomStages.count 41 | { 42 | return zoomStages.last! 43 | } 44 | else if index < 0 45 | { 46 | return zoomStages.first! 47 | } 48 | else 49 | { 50 | return zoomStages[index] 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /DynamicGridZoom/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DynamicGridZoom 2 | 3 | SwiftUI implementation of dynamic sizing for elements in a Grid using magnification/pinching gestures (as seen in the Apple's Photos app) 4 | 5 | https://github.com/AlexanderMarchant/DynamicGridZoom/assets/26875793/869d54f6-19a8-4c7d-bb7e-b06b4fd45a18 6 | 7 | --------------------------------------------------------------------------------