├── .gitignore ├── ATPagingByCell ├── ATPagingByCell.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── ATPagingByCell │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── AppStoreCompositionalLayoutController.h │ ├── AppStoreCompositionalLayoutController.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── SceneDelegate.h │ ├── SceneDelegate.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── LICENSE ├── README.md ├── emoji0.gif └── emoji1.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | # CocoaPods 34 | # 35 | # We recommend against adding the Pods directory to your .gitignore. However 36 | # you should judge for yourself, the pros and cons are mentioned at: 37 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 38 | # 39 | # Pods/ 40 | # 41 | # Add this line if you want to avoid checking in source code from the Xcode workspace 42 | # *.xcworkspace 43 | 44 | # Carthage 45 | # 46 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 47 | # Carthage/Checkouts 48 | 49 | Carthage/Build/ 50 | 51 | # fastlane 52 | # 53 | # It is recommended to not store the screenshots in the git repo. 54 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 55 | # For more information about the recommended setup visit: 56 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 57 | 58 | fastlane/report.xml 59 | fastlane/Preview.html 60 | fastlane/screenshots/**/*.png 61 | fastlane/test_output 62 | 63 | # Code Injection 64 | # 65 | # After new code Injection tools there's a generated folder /iOSInjectionProject 66 | # https://github.com/johnno1962/injectionforxcode 67 | 68 | iOSInjectionProject/ 69 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6D27C33D24BC313F00B16251 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D27C33C24BC313F00B16251 /* AppDelegate.m */; }; 11 | 6D27C34024BC313F00B16251 /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D27C33F24BC313F00B16251 /* SceneDelegate.m */; }; 12 | 6D27C34324BC313F00B16251 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D27C34224BC313F00B16251 /* ViewController.m */; }; 13 | 6D27C34624BC313F00B16251 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6D27C34424BC313F00B16251 /* Main.storyboard */; }; 14 | 6D27C34824BC314200B16251 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6D27C34724BC314200B16251 /* Assets.xcassets */; }; 15 | 6D27C34B24BC314200B16251 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6D27C34924BC314200B16251 /* LaunchScreen.storyboard */; }; 16 | 6D27C34E24BC314200B16251 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D27C34D24BC314200B16251 /* main.m */; }; 17 | 6D63B3A824BE9C1B001B0838 /* AppStoreCompositionalLayoutController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D63B3A724BE9C1B001B0838 /* AppStoreCompositionalLayoutController.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 6D27C33824BC313F00B16251 /* ATPagingByCell.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ATPagingByCell.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 6D27C33B24BC313F00B16251 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | 6D27C33C24BC313F00B16251 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | 6D27C33E24BC313F00B16251 /* SceneDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SceneDelegate.h; sourceTree = ""; }; 25 | 6D27C33F24BC313F00B16251 /* SceneDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SceneDelegate.m; sourceTree = ""; }; 26 | 6D27C34124BC313F00B16251 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | 6D27C34224BC313F00B16251 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | 6D27C34524BC313F00B16251 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | 6D27C34724BC314200B16251 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | 6D27C34A24BC314200B16251 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | 6D27C34C24BC314200B16251 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 6D27C34D24BC314200B16251 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 33 | 6D63B3A624BE9C1B001B0838 /* AppStoreCompositionalLayoutController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppStoreCompositionalLayoutController.h; sourceTree = ""; }; 34 | 6D63B3A724BE9C1B001B0838 /* AppStoreCompositionalLayoutController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppStoreCompositionalLayoutController.m; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 6D27C33524BC313F00B16251 /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 6D27C32F24BC313F00B16251 = { 49 | isa = PBXGroup; 50 | children = ( 51 | 6D27C33A24BC313F00B16251 /* ATPagingByCell */, 52 | 6D27C33924BC313F00B16251 /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 6D27C33924BC313F00B16251 /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 6D27C33824BC313F00B16251 /* ATPagingByCell.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 6D27C33A24BC313F00B16251 /* ATPagingByCell */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 6D27C33B24BC313F00B16251 /* AppDelegate.h */, 68 | 6D27C33C24BC313F00B16251 /* AppDelegate.m */, 69 | 6D27C33E24BC313F00B16251 /* SceneDelegate.h */, 70 | 6D27C33F24BC313F00B16251 /* SceneDelegate.m */, 71 | 6D27C34124BC313F00B16251 /* ViewController.h */, 72 | 6D27C34224BC313F00B16251 /* ViewController.m */, 73 | 6D27C34424BC313F00B16251 /* Main.storyboard */, 74 | 6D27C34724BC314200B16251 /* Assets.xcassets */, 75 | 6D27C34924BC314200B16251 /* LaunchScreen.storyboard */, 76 | 6D27C34C24BC314200B16251 /* Info.plist */, 77 | 6D27C34D24BC314200B16251 /* main.m */, 78 | 6D63B3A624BE9C1B001B0838 /* AppStoreCompositionalLayoutController.h */, 79 | 6D63B3A724BE9C1B001B0838 /* AppStoreCompositionalLayoutController.m */, 80 | ); 81 | path = ATPagingByCell; 82 | sourceTree = ""; 83 | }; 84 | /* End PBXGroup section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | 6D27C33724BC313F00B16251 /* ATPagingByCell */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = 6D27C35124BC314200B16251 /* Build configuration list for PBXNativeTarget "ATPagingByCell" */; 90 | buildPhases = ( 91 | 6D27C33424BC313F00B16251 /* Sources */, 92 | 6D27C33524BC313F00B16251 /* Frameworks */, 93 | 6D27C33624BC313F00B16251 /* Resources */, 94 | ); 95 | buildRules = ( 96 | ); 97 | dependencies = ( 98 | ); 99 | name = ATPagingByCell; 100 | productName = ATPagingByCell; 101 | productReference = 6D27C33824BC313F00B16251 /* ATPagingByCell.app */; 102 | productType = "com.apple.product-type.application"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | 6D27C33024BC313F00B16251 /* Project object */ = { 108 | isa = PBXProject; 109 | attributes = { 110 | LastUpgradeCheck = 1150; 111 | ORGANIZATIONNAME = ApesTalk; 112 | TargetAttributes = { 113 | 6D27C33724BC313F00B16251 = { 114 | CreatedOnToolsVersion = 11.5; 115 | }; 116 | }; 117 | }; 118 | buildConfigurationList = 6D27C33324BC313F00B16251 /* Build configuration list for PBXProject "ATPagingByCell" */; 119 | compatibilityVersion = "Xcode 9.3"; 120 | developmentRegion = en; 121 | hasScannedForEncodings = 0; 122 | knownRegions = ( 123 | en, 124 | Base, 125 | ); 126 | mainGroup = 6D27C32F24BC313F00B16251; 127 | productRefGroup = 6D27C33924BC313F00B16251 /* Products */; 128 | projectDirPath = ""; 129 | projectRoot = ""; 130 | targets = ( 131 | 6D27C33724BC313F00B16251 /* ATPagingByCell */, 132 | ); 133 | }; 134 | /* End PBXProject section */ 135 | 136 | /* Begin PBXResourcesBuildPhase section */ 137 | 6D27C33624BC313F00B16251 /* Resources */ = { 138 | isa = PBXResourcesBuildPhase; 139 | buildActionMask = 2147483647; 140 | files = ( 141 | 6D27C34B24BC314200B16251 /* LaunchScreen.storyboard in Resources */, 142 | 6D27C34824BC314200B16251 /* Assets.xcassets in Resources */, 143 | 6D27C34624BC313F00B16251 /* Main.storyboard in Resources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXResourcesBuildPhase section */ 148 | 149 | /* Begin PBXSourcesBuildPhase section */ 150 | 6D27C33424BC313F00B16251 /* Sources */ = { 151 | isa = PBXSourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | 6D27C34324BC313F00B16251 /* ViewController.m in Sources */, 155 | 6D27C33D24BC313F00B16251 /* AppDelegate.m in Sources */, 156 | 6D27C34E24BC314200B16251 /* main.m in Sources */, 157 | 6D63B3A824BE9C1B001B0838 /* AppStoreCompositionalLayoutController.m in Sources */, 158 | 6D27C34024BC313F00B16251 /* SceneDelegate.m in Sources */, 159 | ); 160 | runOnlyForDeploymentPostprocessing = 0; 161 | }; 162 | /* End PBXSourcesBuildPhase section */ 163 | 164 | /* Begin PBXVariantGroup section */ 165 | 6D27C34424BC313F00B16251 /* Main.storyboard */ = { 166 | isa = PBXVariantGroup; 167 | children = ( 168 | 6D27C34524BC313F00B16251 /* Base */, 169 | ); 170 | name = Main.storyboard; 171 | sourceTree = ""; 172 | }; 173 | 6D27C34924BC314200B16251 /* LaunchScreen.storyboard */ = { 174 | isa = PBXVariantGroup; 175 | children = ( 176 | 6D27C34A24BC314200B16251 /* Base */, 177 | ); 178 | name = LaunchScreen.storyboard; 179 | sourceTree = ""; 180 | }; 181 | /* End PBXVariantGroup section */ 182 | 183 | /* Begin XCBuildConfiguration section */ 184 | 6D27C34F24BC314200B16251 /* Debug */ = { 185 | isa = XCBuildConfiguration; 186 | buildSettings = { 187 | ALWAYS_SEARCH_USER_PATHS = NO; 188 | CLANG_ANALYZER_NONNULL = YES; 189 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 190 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 191 | CLANG_CXX_LIBRARY = "libc++"; 192 | CLANG_ENABLE_MODULES = YES; 193 | CLANG_ENABLE_OBJC_ARC = YES; 194 | CLANG_ENABLE_OBJC_WEAK = YES; 195 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 196 | CLANG_WARN_BOOL_CONVERSION = YES; 197 | CLANG_WARN_COMMA = YES; 198 | CLANG_WARN_CONSTANT_CONVERSION = YES; 199 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 200 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 201 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 202 | CLANG_WARN_EMPTY_BODY = YES; 203 | CLANG_WARN_ENUM_CONVERSION = YES; 204 | CLANG_WARN_INFINITE_RECURSION = YES; 205 | CLANG_WARN_INT_CONVERSION = YES; 206 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 207 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 208 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 209 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 210 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 211 | CLANG_WARN_STRICT_PROTOTYPES = YES; 212 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 213 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 214 | CLANG_WARN_UNREACHABLE_CODE = YES; 215 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 216 | COPY_PHASE_STRIP = NO; 217 | DEBUG_INFORMATION_FORMAT = dwarf; 218 | ENABLE_STRICT_OBJC_MSGSEND = YES; 219 | ENABLE_TESTABILITY = YES; 220 | GCC_C_LANGUAGE_STANDARD = gnu11; 221 | GCC_DYNAMIC_NO_PIC = NO; 222 | GCC_NO_COMMON_BLOCKS = YES; 223 | GCC_OPTIMIZATION_LEVEL = 0; 224 | GCC_PREPROCESSOR_DEFINITIONS = ( 225 | "DEBUG=1", 226 | "$(inherited)", 227 | ); 228 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 229 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 230 | GCC_WARN_UNDECLARED_SELECTOR = YES; 231 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 232 | GCC_WARN_UNUSED_FUNCTION = YES; 233 | GCC_WARN_UNUSED_VARIABLE = YES; 234 | IPHONEOS_DEPLOYMENT_TARGET = 13.5; 235 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 236 | MTL_FAST_MATH = YES; 237 | ONLY_ACTIVE_ARCH = YES; 238 | SDKROOT = iphoneos; 239 | }; 240 | name = Debug; 241 | }; 242 | 6D27C35024BC314200B16251 /* Release */ = { 243 | isa = XCBuildConfiguration; 244 | buildSettings = { 245 | ALWAYS_SEARCH_USER_PATHS = NO; 246 | CLANG_ANALYZER_NONNULL = YES; 247 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 248 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 249 | CLANG_CXX_LIBRARY = "libc++"; 250 | CLANG_ENABLE_MODULES = YES; 251 | CLANG_ENABLE_OBJC_ARC = YES; 252 | CLANG_ENABLE_OBJC_WEAK = YES; 253 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 254 | CLANG_WARN_BOOL_CONVERSION = YES; 255 | CLANG_WARN_COMMA = YES; 256 | CLANG_WARN_CONSTANT_CONVERSION = YES; 257 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 258 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 259 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 260 | CLANG_WARN_EMPTY_BODY = YES; 261 | CLANG_WARN_ENUM_CONVERSION = YES; 262 | CLANG_WARN_INFINITE_RECURSION = YES; 263 | CLANG_WARN_INT_CONVERSION = YES; 264 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 265 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 266 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 267 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 268 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 269 | CLANG_WARN_STRICT_PROTOTYPES = YES; 270 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 271 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 272 | CLANG_WARN_UNREACHABLE_CODE = YES; 273 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 274 | COPY_PHASE_STRIP = NO; 275 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 276 | ENABLE_NS_ASSERTIONS = NO; 277 | ENABLE_STRICT_OBJC_MSGSEND = YES; 278 | GCC_C_LANGUAGE_STANDARD = gnu11; 279 | GCC_NO_COMMON_BLOCKS = YES; 280 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 281 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 282 | GCC_WARN_UNDECLARED_SELECTOR = YES; 283 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 284 | GCC_WARN_UNUSED_FUNCTION = YES; 285 | GCC_WARN_UNUSED_VARIABLE = YES; 286 | IPHONEOS_DEPLOYMENT_TARGET = 13.5; 287 | MTL_ENABLE_DEBUG_INFO = NO; 288 | MTL_FAST_MATH = YES; 289 | SDKROOT = iphoneos; 290 | VALIDATE_PRODUCT = YES; 291 | }; 292 | name = Release; 293 | }; 294 | 6D27C35224BC314200B16251 /* Debug */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 298 | CODE_SIGN_STYLE = Automatic; 299 | DEVELOPMENT_TEAM = ""; 300 | INFOPLIST_FILE = ATPagingByCell/Info.plist; 301 | LD_RUNPATH_SEARCH_PATHS = ( 302 | "$(inherited)", 303 | "@executable_path/Frameworks", 304 | ); 305 | PRODUCT_BUNDLE_IDENTIFIER = com.github.ApesTalk.ATPagingByCell; 306 | PRODUCT_NAME = "$(TARGET_NAME)"; 307 | TARGETED_DEVICE_FAMILY = "1,2"; 308 | }; 309 | name = Debug; 310 | }; 311 | 6D27C35324BC314200B16251 /* Release */ = { 312 | isa = XCBuildConfiguration; 313 | buildSettings = { 314 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 315 | CODE_SIGN_STYLE = Automatic; 316 | DEVELOPMENT_TEAM = ""; 317 | INFOPLIST_FILE = ATPagingByCell/Info.plist; 318 | LD_RUNPATH_SEARCH_PATHS = ( 319 | "$(inherited)", 320 | "@executable_path/Frameworks", 321 | ); 322 | PRODUCT_BUNDLE_IDENTIFIER = com.github.ApesTalk.ATPagingByCell; 323 | PRODUCT_NAME = "$(TARGET_NAME)"; 324 | TARGETED_DEVICE_FAMILY = "1,2"; 325 | }; 326 | name = Release; 327 | }; 328 | /* End XCBuildConfiguration section */ 329 | 330 | /* Begin XCConfigurationList section */ 331 | 6D27C33324BC313F00B16251 /* Build configuration list for PBXProject "ATPagingByCell" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | 6D27C34F24BC314200B16251 /* Debug */, 335 | 6D27C35024BC314200B16251 /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | 6D27C35124BC314200B16251 /* Build configuration list for PBXNativeTarget "ATPagingByCell" */ = { 341 | isa = XCConfigurationList; 342 | buildConfigurations = ( 343 | 6D27C35224BC314200B16251 /* Debug */, 344 | 6D27C35324BC314200B16251 /* Release */, 345 | ); 346 | defaultConfigurationIsVisible = 0; 347 | defaultConfigurationName = Release; 348 | }; 349 | /* End XCConfigurationList section */ 350 | }; 351 | rootObject = 6D27C33024BC313F00B16251 /* Project object */; 352 | } 353 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ATPagingByCell 4 | // 5 | // Created by ApesTalk on 2020/7/13. 6 | // Copyright © 2020 https://github.com/ApesTalk All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ATPagingByCell 4 | // 5 | // Created by ApesTalk on 2020/7/13. 6 | // Copyright © 2020 https://github.com/ApesTalk All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | #pragma mark - UISceneSession lifecycle 25 | 26 | 27 | - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options { 28 | // Called when a new scene session is being created. 29 | // Use this method to select a configuration to create the new scene with. 30 | return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; 31 | } 32 | 33 | 34 | - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions { 35 | // Called when the user discards a scene session. 36 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 37 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 38 | } 39 | 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/AppStoreCompositionalLayoutController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppStoreCompositionalLayoutController.h 3 | // ATPagingByCell 4 | // 5 | // Created by ApesTalk on 2020/7/15. 6 | // Copyright © 2020 https://github.com/ApesTalk All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface AppStoreCompositionalLayoutController : UIViewController 13 | 14 | @end 15 | 16 | /* 17 | 18 | 0.如何组合样式?item和group嵌套 19 | 1.横向滚动的section 如何一上来滚动到指定位置 20 | 2.怎么检测到滚动到指定cell进行播放的切换 visibleItemsInvalidationHandler回调里处理 21 | 22 | https://developer.apple.com/videos/play/wwdc2019/215/ 23 | 24 | https://developer.apple.com/documentation/uikit/uicollectionviewcompositionallayout 25 | https://developer.apple.com/documentation/uikit/views_and_controls/collection_views/implementing_modern_collection_views 26 | https://juejin.im/post/5ee5e90ee51d4578a6798b9e 27 | https://juejin.im/post/5d00c430f265da1b8466de01 28 | */ 29 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/AppStoreCompositionalLayoutController.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppStoreCompositionalLayoutController.m 3 | // ATPagingByCell 4 | // 5 | // Created by ApesTalk on 2020/7/15. 6 | // Copyright © 2020 https://github.com/ApesTalk All rights reserved. 7 | // 8 | 9 | #import "AppStoreCompositionalLayoutController.h" 10 | 11 | @interface MyDecorateView : UICollectionReusableView 12 | 13 | @end 14 | 15 | @implementation MyDecorateView 16 | 17 | - (instancetype)initWithFrame:(CGRect)frame 18 | { 19 | if(self = [super initWithFrame:frame]){ 20 | self.layer.cornerRadius = 10; 21 | self.layer.masksToBounds = YES; 22 | self.backgroundColor = [UIColor redColor]; 23 | self.layer.borderWidth = 2; 24 | self.layer.borderColor = [UIColor lightGrayColor].CGColor; 25 | } 26 | return self; 27 | } 28 | 29 | @end 30 | 31 | 32 | 33 | 34 | @interface AppStoreCompositionalLayoutController () 35 | @property (nonatomic, assign) NSInteger demoType; 36 | @property (nonatomic, copy) NSArray *sectionTitles; 37 | @property (nonatomic, strong) UICollectionView *collectionView; 38 | @end 39 | 40 | @implementation AppStoreCompositionalLayoutController 41 | 42 | - (void)viewDidLoad { 43 | [super viewDidLoad]; 44 | // Do any additional setup after loading the view. 45 | self.view.backgroundColor = [UIColor whiteColor]; 46 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; 47 | [btn setTitle:@"Dimiss" forState:UIControlStateNormal]; 48 | btn.frame = CGRectMake(0, 44, 60, 44); 49 | [btn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 50 | [self.view addSubview:btn]; 51 | 52 | UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(60, 44, self.view.bounds.size.width-120, 44)]; 53 | lbl.textAlignment = NSTextAlignmentCenter; 54 | lbl.text = @"AppStore布局效果"; 55 | [self.view addSubview:lbl]; 56 | 57 | //一.决定元素大小的 NSCollectionLayoutDimension、NSCollectionLayoutSize 58 | //1.尺寸相当于父视图的比例 59 | NSCollectionLayoutDimension *widthDismension = [NSCollectionLayoutDimension fractionalWidthDimension:0.2]; 60 | //2.固定尺寸值 61 | widthDismension = [NSCollectionLayoutDimension absoluteDimension:100]; 62 | //3.预估值 63 | widthDismension = [NSCollectionLayoutDimension estimatedDimension:99]; 64 | 65 | NSCollectionLayoutDimension *heightDismension = [NSCollectionLayoutDimension fractionalWidthDimension:0.2]; 66 | 67 | NSCollectionLayoutSize *size = [NSCollectionLayoutSize sizeWithWidthDimension:widthDismension heightDimension:heightDismension]; 68 | 69 | 70 | 71 | //二.决定Item布局的 NSCollectionLayoutItem 72 | NSCollectionLayoutItem *item = [NSCollectionLayoutItem itemWithLayoutSize:size]; 73 | 74 | 75 | //三.决定Gropu布局的 NSCollectionLayoutGroup(继承于NSCollectionLayoutItem) 水平、垂直、自定义三种形式 76 | NSCollectionLayoutGroup *group = [NSCollectionLayoutGroup horizontalGroupWithLayoutSize:size subitems:@[item]]; 77 | 78 | //四.决定Section布局的 NSCollectionLayoutSection 79 | NSCollectionLayoutSection *section = [NSCollectionLayoutSection sectionWithGroup:group]; 80 | 81 | 82 | 83 | 84 | // [self demo0]; 85 | // [self demo1]; 86 | [self demo2]; 87 | // [self demo3]; 88 | // [self demo4]; 89 | } 90 | 91 | - (void)dismiss 92 | { 93 | [self dismissViewControllerAnimated:YES completion:nil]; 94 | } 95 | 96 | 97 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 98 | { 99 | return _demoType == 2 ? _sectionTitles.count : 2; 100 | } 101 | 102 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 103 | { 104 | // return section == 0 ? 5 : 2; 105 | return 8; 106 | } 107 | 108 | 109 | /* 110 | !!!!:numberOfSections和numberOfItems跟NSCollectionLayoutSection、NSCollectionLayoutGroup、NSCollectionLayoutItem的关系 111 | 由于一个UICollectionViewCompositionalLayout只能指定一个NSCollectionLayoutSection,一个NSCollectionLayoutSection只能指定一个NSCollectionLayoutGroup。 112 | 113 | 对于demo1来说: 114 | 1.如果numberOfSections=1,numberOfItems>3,每3个cell对应一个group布局样式,超过3的继续分group 115 | 2.如果numberOfSections=2,numberOfItems=2, 每2个cell对应一个group布局样式,分为两个group 116 | 117 | 也就是说numberOfSections对应的每一个section开始布局的时候一定会开始一个group的布局了(即使上一个section对应的rows不是group中样式数量的整数倍,该section的第一个cell也不会接着布局)。每个section中的cell会按group中对应的样式依次布局。 118 | 119 | */ 120 | 121 | 122 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 123 | { 124 | UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; 125 | cell.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.f green:arc4random()%255/255.f blue:arc4random()%255/255.f alpha:1]; 126 | return cell; 127 | } 128 | 129 | 130 | - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath 131 | { 132 | if(_demoType == 2){ 133 | if([kind isEqualToString:UICollectionElementKindSectionHeader]){ 134 | UICollectionReusableView *h = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"head" forIndexPath:indexPath]; 135 | UILabel *l = [h viewWithTag:1000]; 136 | if(!l){ 137 | l = [UILabel new]; 138 | l.frame = h.bounds; 139 | l.tag = 1000; 140 | [h addSubview:l]; 141 | } 142 | l.text = _sectionTitles[indexPath.section]; 143 | return h; 144 | } 145 | } 146 | 147 | if([kind isEqualToString:UICollectionElementKindSectionHeader]){ 148 | UICollectionReusableView *h = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"head" forIndexPath:indexPath]; 149 | UILabel *l = [h viewWithTag:1000]; 150 | if(!l){ 151 | l = [UILabel new]; 152 | l.text = @"Section Header"; 153 | l.frame = h.bounds; 154 | l.tag = 1000; 155 | [h addSubview:l]; 156 | } 157 | return h; 158 | } else if([kind isEqualToString:UICollectionElementKindSectionFooter]){ 159 | UICollectionReusableView *f = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"foot" forIndexPath:indexPath]; 160 | UILabel *l = [f viewWithTag:1000]; 161 | if(!l){ 162 | l = [UILabel new]; 163 | l.text = @"Section Footer"; 164 | l.frame = f.bounds; 165 | l.tag = 1000; 166 | [f addSubview:l]; 167 | } 168 | return f; 169 | } else if([kind isEqualToString:@"Badge"]){ 170 | UICollectionReusableView *b = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"custom" forIndexPath:indexPath]; 171 | b.backgroundColor = [UIColor blackColor]; 172 | b.layer.cornerRadius = 10; 173 | b.layer.masksToBounds = YES; 174 | return b; 175 | } 176 | return nil; 177 | } 178 | 179 | 180 | 181 | 182 | 183 | //水平滚动,但cell大小交替变换,且cell居中对齐。比瀑布流UICollectionViewFlowLayout方式确实方便一些。 184 | - (void)demo0 185 | { 186 | _demoType = 0; 187 | 188 | NSCollectionLayoutSize *itemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:0.5] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1.0]]; 189 | NSCollectionLayoutItem *item = [NSCollectionLayoutItem itemWithLayoutSize:itemSize]; 190 | 191 | NSCollectionLayoutSize *itemSize1 = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:0.25] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:0.5]]; 192 | NSCollectionLayoutItem *item1 = [NSCollectionLayoutItem itemWithLayoutSize:itemSize1]; 193 | // item1.contentInsets = NSDirectionalEdgeInsetsMake(20, 20, 20, 20);//内边距 会改变其size 194 | // item1.edgeSpacing = [NSCollectionLayoutEdgeSpacing spacingForLeading:nil top:[NSCollectionLayoutSpacing flexibleSpacing:10] trailing:nil bottom:nil];//外边距,值可能会被优化 【相对于group底部对齐】 195 | item1.edgeSpacing = [NSCollectionLayoutEdgeSpacing spacingForLeading:[NSCollectionLayoutSpacing flexibleSpacing:10] top:[NSCollectionLayoutSpacing flexibleSpacing:10] trailing:[NSCollectionLayoutSpacing flexibleSpacing:10] bottom:[NSCollectionLayoutSpacing flexibleSpacing:10]];//【相对于group居中对齐】 196 | 197 | //一个group可以指定多个item,指定多个,对应的cell会按items的样式依次布局 198 | NSCollectionLayoutSize *groupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalWidthDimension:0.25]]; 199 | NSCollectionLayoutGroup *group = [NSCollectionLayoutGroup horizontalGroupWithLayoutSize:groupSize subitems:@[item, item1]]; 200 | //interItemSpacing对指定了多个subitems才有效 201 | group.interItemSpacing = [NSCollectionLayoutSpacing fixedSpacing:5]; 202 | 203 | //一个section只能指定一个group 204 | NSCollectionLayoutSection *section = [NSCollectionLayoutSection sectionWithGroup:group]; 205 | section.contentInsets = NSDirectionalEdgeInsetsFromString(@"{5.0, 5.0, 5.0, 5.0}"); 206 | 207 | 208 | //Orthogonal正交 在正交轴上怎么滚动? 209 | // section.orthogonalScrollingBehavior = UICollectionLayoutSectionOrthogonalScrollingBehaviorGroupPaging; 210 | // section.decorationItems = 211 | UICollectionViewCompositionalLayoutConfiguration *config = [UICollectionViewCompositionalLayoutConfiguration new]; 212 | config.scrollDirection = UICollectionViewScrollDirectionHorizontal;//水平滚动 213 | 214 | //layout只能指定一个section 215 | UICollectionViewCompositionalLayout *layout = [[UICollectionViewCompositionalLayout alloc]initWithSection:section configuration:config]; 216 | 217 | 218 | UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height-100) collectionViewLayout:layout]; 219 | self.collectionView = collectionView; 220 | collectionView.backgroundColor = [UIColor lightGrayColor]; 221 | [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; 222 | collectionView.dataSource = self; 223 | collectionView.delegate = self; 224 | [self.view addSubview:collectionView]; 225 | } 226 | 227 | 228 | 229 | 230 | 231 | 232 | //垂直滚动,一个大cell + 两个小cell 233 | - (void)demo1 234 | { 235 | _demoType = 1; 236 | 237 | 238 | //配置装饰 239 | NSCollectionLayoutAnchor *badgeAnchor = [NSCollectionLayoutAnchor layoutAnchorWithEdges:NSDirectionalRectEdgeTop|NSDirectionalRectEdgeTrailing fractionalOffset:CGPointMake(0.5, -0.5)];//装饰视图中心点等于cell的右上角顶点 240 | NSCollectionLayoutSize *badgeSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:20] heightDimension:[NSCollectionLayoutDimension absoluteDimension:20]]; 241 | NSCollectionLayoutSupplementaryItem *badge = [NSCollectionLayoutSupplementaryItem supplementaryItemWithLayoutSize:badgeSize elementKind:@"Badge" containerAnchor:badgeAnchor]; 242 | 243 | //顶部item 244 | NSCollectionLayoutSize *topItemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalWidthDimension:9.0/16.0]]; 245 | NSCollectionLayoutItem *topItem = [NSCollectionLayoutItem itemWithLayoutSize:topItemSize]; 246 | 247 | //底部item 248 | NSCollectionLayoutSize *bottomItemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:0.5] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1.0]]; 249 | NSCollectionLayoutItem *bottomItem = [NSCollectionLayoutItem itemWithLayoutSize:bottomItemSize supplementaryItems:@[badge]]; 250 | bottomItem.contentInsets = NSDirectionalEdgeInsetsMake(8, 8, 8, 8); 251 | 252 | //底部group 253 | NSCollectionLayoutSize *bottomGroupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalWidthDimension:0.5]]; 254 | // NSCollectionLayoutGroup *bottomGroup = [NSCollectionLayoutGroup horizontalGroupWithLayoutSize:bottomGroupSize subitems:@[bottomItem, bottomItem]];//该api放两个相同的item是不起效的 255 | NSCollectionLayoutGroup *bottomGroup = [NSCollectionLayoutGroup horizontalGroupWithLayoutSize:bottomGroupSize subitem:bottomItem count:2];//会在这个分组中放入两个相同的item。并且这里设置了2,即使bottomItemSize width设置比较大,依然会平分 256 | 257 | //组合group 🐂🍺 注意这里的尺寸一点要是组合的大小 258 | NSCollectionLayoutSize *fullGroupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalWidthDimension:9.0/16.0 + 0.5]]; 259 | NSCollectionLayoutGroup *nestedGroup = [NSCollectionLayoutGroup verticalGroupWithLayoutSize:fullGroupSize subitems:@[topItem, bottomGroup]];//NSCollectionLayoutGroup继承自NSCollectionLayoutItem 260 | 261 | 262 | 263 | 264 | //虽然一个section只能指定一个group,但可以group中可以组合item和其他group 265 | NSCollectionLayoutSection *section = [NSCollectionLayoutSection sectionWithGroup:nestedGroup]; 266 | // section.orthogonalScrollingBehavior = UICollectionLayoutSectionOrthogonalScrollingBehaviorContinuous; 267 | 268 | NSCollectionLayoutSize *headerSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension estimatedDimension:44]]; 269 | NSCollectionLayoutBoundarySupplementaryItem *headerItem = [NSCollectionLayoutBoundarySupplementaryItem boundarySupplementaryItemWithLayoutSize:headerSize elementKind:UICollectionElementKindSectionHeader alignment:NSRectAlignmentTop]; 270 | // headerItem.pinToVisibleBounds = YES; 271 | 272 | //配置组头组尾 273 | NSCollectionLayoutSize *footerSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension estimatedDimension:60]]; 274 | NSCollectionLayoutBoundarySupplementaryItem *footerItem = [NSCollectionLayoutBoundarySupplementaryItem boundarySupplementaryItemWithLayoutSize:footerSize elementKind:UICollectionElementKindSectionFooter alignment:NSRectAlignmentBottom]; 275 | 276 | section.boundarySupplementaryItems = @[headerItem, footerItem]; 277 | 278 | 279 | 280 | UICollectionViewCompositionalLayout *layout = [[UICollectionViewCompositionalLayout alloc]initWithSection:section]; 281 | 282 | UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height - 100) collectionViewLayout:layout]; 283 | self.collectionView = collectionView; 284 | collectionView.backgroundColor = [UIColor lightGrayColor]; 285 | [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; 286 | [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"]; 287 | [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"foot"]; 288 | [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:@"Badge" withReuseIdentifier:@"custom"]; 289 | 290 | collectionView.dataSource = self; 291 | collectionView.delegate = self; 292 | [self.view addSubview:collectionView]; 293 | } 294 | 295 | 296 | //仿AppStore的游戏和app tab页面布局 297 | - (void)demo2 298 | { 299 | _demoType = 2; 300 | _sectionTitles = @[@"强烈推荐", @"热门App", @"大家都在用", @"今天看什么", @"新鲜App", @"给小朋友", @"热门类别", @"生活微记录", @"合影不受限", @"付费App排行", @"免费App排行", @"快速链接"]; 301 | 302 | UICollectionViewCompositionalLayoutConfiguration *config = [UICollectionViewCompositionalLayoutConfiguration new]; 303 | config.interSectionSpacing = 30;//不同section之间的间距 304 | 305 | 306 | UICollectionViewCompositionalLayout *layout = [[UICollectionViewCompositionalLayout alloc]initWithSectionProvider:^NSCollectionLayoutSection * _Nullable(NSInteger section, id environment) { 307 | return [self generateSectionForSection:section]; 308 | }]; 309 | layout.configuration = config; 310 | 311 | 312 | UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height-100) collectionViewLayout:layout]; 313 | self.collectionView = collectionView; 314 | collectionView.backgroundColor = [UIColor lightGrayColor]; 315 | [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; 316 | [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"]; 317 | // [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"foot"]; 318 | // [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:@"Badge" withReuseIdentifier:@"custom"]; 319 | collectionView.dataSource = self; 320 | collectionView.delegate = self; 321 | [self.view addSubview:collectionView]; 322 | 323 | } 324 | 325 | - (NSCollectionLayoutSection *)generateSectionForSection:(NSInteger)section 326 | { 327 | NSCollectionLayoutGroup *group; 328 | NSDirectionalEdgeInsets sectionInsets = NSDirectionalEdgeInsetsMake(0, 0, 0, 0); 329 | UICollectionLayoutSectionOrthogonalScrollingBehavior behavior = UICollectionLayoutSectionOrthogonalScrollingBehaviorContinuous; 330 | switch (section) { 331 | case 0: 332 | case 5: 333 | { 334 | //顶部banner item 335 | //效果:paging by cell 看起来cell距离屏幕左右各20像素 336 | sectionInsets = NSDirectionalEdgeInsetsMake(0, 15, 0, 15); 337 | /* 338 | UICollectionLayoutSectionOrthogonalScrollingBehaviorContinuous 正常连续滚动 339 | UICollectionLayoutSectionOrthogonalScrollingBehaviorPaging 正常分页轮播(页宽等于UICollectionView的宽度) 340 | UICollectionLayoutSectionOrthogonalScrollingBehaviorContinuousGroupLeadingBoundary 停止滚动时一定会停留在group的边界处 341 | UICollectionLayoutSectionOrthogonalScrollingBehaviorGroupPaging 按group的尺寸进行分页 342 | UICollectionLayoutSectionOrthogonalScrollingBehaviorGroupPagingCentered 也是按group的尺寸进行分页,但会沿正交轴增加首尾间距让其居中 343 | */ 344 | behavior = UICollectionLayoutSectionOrthogonalScrollingBehaviorGroupPaging;//完美的paging by cell效果 345 | 346 | CGFloat bannerSize = [UIScreen mainScreen].bounds.size.width - 30;//原本占screenwidth-30 347 | NSCollectionLayoutSize *bannerItemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1.0]]; 348 | NSCollectionLayoutItem *bannerItem = [NSCollectionLayoutItem itemWithLayoutSize:bannerItemSize]; 349 | bannerItem.contentInsets = NSDirectionalEdgeInsetsMake(0, 5, 0, 5);//左右各收缩5像素 占screenwidth-40 350 | 351 | NSCollectionLayoutSize *bannerGroupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:bannerSize] heightDimension:[NSCollectionLayoutDimension absoluteDimension:bannerSize]]; 352 | group = [NSCollectionLayoutGroup horizontalGroupWithLayoutSize:bannerGroupSize subitem:bannerItem count:1];//水平 353 | break; 354 | } 355 | case 1: 356 | case 2: 357 | case 4: 358 | case 7: 359 | case 9: 360 | case 10: 361 | { 362 | //每列三行的cell样式 363 | sectionInsets = NSDirectionalEdgeInsetsMake(0, 15, 0, 15); 364 | behavior = UICollectionLayoutSectionOrthogonalScrollingBehaviorGroupPaging;//完美的paging by cell效果 365 | 366 | CGFloat oneThirdWidth = [UIScreen mainScreen].bounds.size.width - 30; 367 | CGFloat oneThirdHeight = 80; 368 | NSCollectionLayoutSize *oneThirdItemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1.0/3.0]]; 369 | NSCollectionLayoutItem *oneThirdItem = [NSCollectionLayoutItem itemWithLayoutSize:oneThirdItemSize]; 370 | oneThirdItem.contentInsets = NSDirectionalEdgeInsetsMake(0, 5, 0, 5); 371 | 372 | NSCollectionLayoutSize *oneThirdGroupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:oneThirdWidth] heightDimension:[NSCollectionLayoutDimension absoluteDimension:oneThirdHeight * 3.0]]; 373 | group = [NSCollectionLayoutGroup verticalGroupWithLayoutSize:oneThirdGroupSize subitem:oneThirdItem count:3];//垂直 374 | 375 | break; 376 | } 377 | case 3: 378 | { 379 | //今天看什么banner 380 | sectionInsets = NSDirectionalEdgeInsetsMake(0, 15, 0, 15); 381 | behavior = UICollectionLayoutSectionOrthogonalScrollingBehaviorGroupPaging;//完美的paging by cell效果 382 | 383 | CGFloat bannerWidth = [UIScreen mainScreen].bounds.size.width - 150; 384 | CGFloat bannerHeight = 180; 385 | NSCollectionLayoutSize *bannerItemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1.0]]; 386 | NSCollectionLayoutItem *bannerItem = [NSCollectionLayoutItem itemWithLayoutSize:bannerItemSize]; 387 | bannerItem.contentInsets = NSDirectionalEdgeInsetsMake(0, 5, 0, 5); 388 | 389 | NSCollectionLayoutSize *bannerGroupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:bannerWidth] heightDimension:[NSCollectionLayoutDimension absoluteDimension:bannerHeight]]; 390 | group = [NSCollectionLayoutGroup horizontalGroupWithLayoutSize:bannerGroupSize subitem:bannerItem count:1];//水平 391 | 392 | break; 393 | } 394 | case 6: 395 | { 396 | //热门类别 397 | sectionInsets = NSDirectionalEdgeInsetsMake(0, 20, 0, 20); 398 | 399 | CGFloat cellWidth = [UIScreen mainScreen].bounds.size.width - 40; 400 | CGFloat cellHeight = 50; 401 | NSCollectionLayoutSize *itemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1.0]]; 402 | NSCollectionLayoutItem *item = [NSCollectionLayoutItem itemWithLayoutSize:itemSize]; 403 | 404 | NSCollectionLayoutSize *groupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:cellWidth] heightDimension:[NSCollectionLayoutDimension absoluteDimension:cellHeight * 8]]; 405 | group = [NSCollectionLayoutGroup verticalGroupWithLayoutSize:groupSize subitem:item count:8];//垂直 406 | break; 407 | } 408 | case 8: 409 | { 410 | //每列两行的cell样式 411 | sectionInsets = NSDirectionalEdgeInsetsMake(0, 15, 0, 15); 412 | behavior = UICollectionLayoutSectionOrthogonalScrollingBehaviorGroupPaging;//完美的paging by cell效果 413 | 414 | CGFloat oneSecondWidth = [UIScreen mainScreen].bounds.size.width - 30; 415 | CGFloat oneSecondHeight = 120; 416 | NSCollectionLayoutSize *oneSecondItemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1.0/2.0]]; 417 | NSCollectionLayoutItem *oneSecondItem = [NSCollectionLayoutItem itemWithLayoutSize:oneSecondItemSize]; 418 | oneSecondItem.contentInsets = NSDirectionalEdgeInsetsMake(0, 5, 0, 5); 419 | 420 | NSCollectionLayoutSize *oneSecondGroupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:oneSecondWidth] heightDimension:[NSCollectionLayoutDimension absoluteDimension:oneSecondHeight * 2.0]]; 421 | group = [NSCollectionLayoutGroup verticalGroupWithLayoutSize:oneSecondGroupSize subitem:oneSecondItem count:2];//垂直 422 | break; 423 | } 424 | case 11: 425 | { 426 | //快速链接 427 | sectionInsets = NSDirectionalEdgeInsetsMake(0, 20, 0, 20); 428 | 429 | CGFloat cellWidth = [UIScreen mainScreen].bounds.size.width - 40; 430 | CGFloat cellHeight = 50; 431 | NSCollectionLayoutSize *itemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1.0]]; 432 | NSCollectionLayoutItem *item = [NSCollectionLayoutItem itemWithLayoutSize:itemSize]; 433 | 434 | NSCollectionLayoutSize *groupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:cellWidth] heightDimension:[NSCollectionLayoutDimension absoluteDimension:cellHeight * 8]]; 435 | group = [NSCollectionLayoutGroup verticalGroupWithLayoutSize:groupSize subitem:item count:8];//垂直 436 | break; 437 | break; 438 | } 439 | } 440 | 441 | NSCollectionLayoutSection *layoutSection = [NSCollectionLayoutSection sectionWithGroup:group]; 442 | layoutSection.orthogonalScrollingBehavior = behavior; 443 | layoutSection.contentInsets = sectionInsets; 444 | if(section == 0){ 445 | layoutSection.visibleItemsInvalidationHandler = ^(NSArray> * _Nonnull visibleItems, CGPoint contentOffset, id _Nonnull layoutEnvironment) { 446 | //这里可以判断哪个cell滚动到了屏幕中心 447 | }; 448 | } 449 | 450 | //配置组头组尾 451 | NSCollectionLayoutSize *headerSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension estimatedDimension:44]]; 452 | NSCollectionLayoutBoundarySupplementaryItem *headerItem = [NSCollectionLayoutBoundarySupplementaryItem boundarySupplementaryItemWithLayoutSize:headerSize elementKind:UICollectionElementKindSectionHeader alignment:NSRectAlignmentTop]; 453 | 454 | layoutSection.boundarySupplementaryItems = @[headerItem]; 455 | 456 | return layoutSection; 457 | } 458 | 459 | 460 | 461 | //垂直布局 类似UITableViewStyleGrouped样式 462 | - (void)demo3 463 | { 464 | _demoType = 3; 465 | 466 | NSCollectionLayoutSize *itemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1.0]]; 467 | NSCollectionLayoutItem *item = [NSCollectionLayoutItem itemWithLayoutSize:itemSize]; 468 | 469 | NSCollectionLayoutSize *groupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension absoluteDimension:44]]; 470 | NSCollectionLayoutGroup *group = [NSCollectionLayoutGroup verticalGroupWithLayoutSize:groupSize subitems:@[item]]; 471 | 472 | NSCollectionLayoutSection *section = [NSCollectionLayoutSection sectionWithGroup:group]; 473 | section.contentInsets = NSDirectionalEdgeInsetsMake(20, 20, 20, 20); 474 | 475 | //group加装饰背景 476 | /* 477 | 1.创建NSCollectionLayoutDecorationItem 它是NSCollectionLayoutItem的子类,不能指定layoutSize。 478 | 2.给NSCollectionLayoutSection的decorationItems赋值。 479 | 3.在UICollectionViewCompositionalLayout上面注册decorationView,在这里注册的类实现样式的自定义。 480 | 注意不是在collectionview上注册SupplementaryView 481 | */ 482 | NSCollectionLayoutDecorationItem *backItem = [NSCollectionLayoutDecorationItem backgroundDecorationItemWithElementKind:@"background"]; 483 | backItem.contentInsets = NSDirectionalEdgeInsetsMake(10, 10, 10, 10); 484 | section.decorationItems = @[backItem]; 485 | 486 | UICollectionViewCompositionalLayoutConfiguration *config = [UICollectionViewCompositionalLayoutConfiguration new]; 487 | config.interSectionSpacing = 20;//不同section之间的间距 488 | 489 | UICollectionViewCompositionalLayout *layout = [[UICollectionViewCompositionalLayout alloc]initWithSection:section configuration:config]; 490 | [layout registerClass:[MyDecorateView class] forDecorationViewOfKind:@"background"]; 491 | 492 | UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height-100) collectionViewLayout:layout]; 493 | self.collectionView = collectionView; 494 | collectionView.backgroundColor = [UIColor lightGrayColor]; 495 | [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; 496 | collectionView.dataSource = self; 497 | collectionView.delegate = self; 498 | [self.view addSubview:collectionView]; 499 | } 500 | 501 | 502 | - (void)demo4 503 | { 504 | _demoType = 4; 505 | 506 | NSCollectionLayoutSize *groupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension absoluteDimension:200]]; 507 | 508 | CGFloat width = [UIScreen mainScreen].bounds.size.width/3.0; 509 | CGFloat height = 200/3.0; 510 | //无法横向滚动 511 | NSCollectionLayoutGroup *group = [NSCollectionLayoutGroup customGroupWithLayoutSize:groupSize itemProvider:^NSArray * _Nonnull(id _Nonnull layoutEnvironment) { 512 | //UICollectionView的每个section走一次 513 | //这里想象空间很大,自己爱咋放咋放 514 | NSMutableArray *arr = [NSMutableArray arrayWithCapacity:8]; 515 | CGFloat x = 0 , y = 0; 516 | for(NSInteger i = 0; i < 8; i++){ 517 | NSCollectionLayoutGroupCustomItem *customItem = [NSCollectionLayoutGroupCustomItem customItemWithFrame:CGRectMake(x, y, width, height) zIndex:1000+i]; 518 | [arr addObject:customItem]; 519 | x += width; 520 | if(i > 0 && i % 3 == 0){ 521 | x = 0; 522 | y += height; 523 | } 524 | } 525 | return arr.copy; 526 | }]; 527 | 528 | NSCollectionLayoutSection *section = [NSCollectionLayoutSection sectionWithGroup:group]; 529 | 530 | UICollectionViewCompositionalLayoutConfiguration *config = [UICollectionViewCompositionalLayoutConfiguration new]; 531 | config.interSectionSpacing = 20;//不同section之间的间距 532 | 533 | UICollectionViewCompositionalLayout *layout = [[UICollectionViewCompositionalLayout alloc]initWithSection:section configuration:config]; 534 | 535 | UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height-100) collectionViewLayout:layout]; 536 | self.collectionView = collectionView; 537 | collectionView.backgroundColor = [UIColor lightGrayColor]; 538 | [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"]; 539 | collectionView.dataSource = self; 540 | collectionView.delegate = self; 541 | [self.view addSubview:collectionView]; 542 | } 543 | 544 | @end 545 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/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 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/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 | 25 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIMainStoryboardFile 45 | Main 46 | UIRequiredDeviceCapabilities 47 | 48 | armv7 49 | 50 | UISupportedInterfaceOrientations 51 | 52 | UIInterfaceOrientationPortrait 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | UISupportedInterfaceOrientations~ipad 57 | 58 | UIInterfaceOrientationPortrait 59 | UIInterfaceOrientationPortraitUpsideDown 60 | UIInterfaceOrientationLandscapeLeft 61 | UIInterfaceOrientationLandscapeRight 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/SceneDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.h 3 | // ATPagingByCell 4 | // 5 | // Created by ApesTalk on 2020/7/13. 6 | // Copyright © 2020 https://github.com/ApesTalk All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SceneDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow * window; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/SceneDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.m 3 | // ATPagingByCell 4 | // 5 | // Created by ApesTalk on 2020/7/13. 6 | // Copyright © 2020 https://github.com/ApesTalk All rights reserved. 7 | // 8 | 9 | #import "SceneDelegate.h" 10 | 11 | @interface SceneDelegate () 12 | 13 | @end 14 | 15 | @implementation SceneDelegate 16 | 17 | 18 | - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { 19 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 20 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 21 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 22 | } 23 | 24 | 25 | - (void)sceneDidDisconnect:(UIScene *)scene { 26 | // Called as the scene is being released by the system. 27 | // This occurs shortly after the scene enters the background, or when its session is discarded. 28 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 29 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 30 | } 31 | 32 | 33 | - (void)sceneDidBecomeActive:(UIScene *)scene { 34 | // Called when the scene has moved from an inactive state to an active state. 35 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 36 | } 37 | 38 | 39 | - (void)sceneWillResignActive:(UIScene *)scene { 40 | // Called when the scene will move from an active state to an inactive state. 41 | // This may occur due to temporary interruptions (ex. an incoming phone call). 42 | } 43 | 44 | 45 | - (void)sceneWillEnterForeground:(UIScene *)scene { 46 | // Called as the scene transitions from the background to the foreground. 47 | // Use this method to undo the changes made on entering the background. 48 | } 49 | 50 | 51 | - (void)sceneDidEnterBackground:(UIScene *)scene { 52 | // Called as the scene transitions from the foreground to the background. 53 | // Use this method to save data, release shared resources, and store enough scene-specific state information 54 | // to restore the scene back to its current state. 55 | } 56 | 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ATPagingByCell 4 | // 5 | // Created by ApesTalk on 2020/7/13. 6 | // Copyright © 2020 https://github.com/ApesTalk All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ATPagingByCell 4 | // 5 | // Created by ApesTalk on 2020/7/13. 6 | // Copyright © 2020 https://github.com/ApesTalk All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "AppStoreCompositionalLayoutController.h" 11 | 12 | @interface EmojiCell : UICollectionViewCell 13 | @property (nonatomic, strong) UILabel *label; 14 | @end 15 | 16 | @implementation EmojiCell 17 | - (instancetype)initWithFrame:(CGRect)frame 18 | { 19 | if(self = [super initWithFrame:frame]){ 20 | self.contentView.backgroundColor = [UIColor lightGrayColor]; 21 | self.contentView.layer.cornerRadius = 16; 22 | self.contentView.layer.masksToBounds = YES; 23 | 24 | _label = [[UILabel alloc]init]; 25 | _label.textColor = [UIColor whiteColor]; 26 | _label.font = [UIFont boldSystemFontOfSize:200]; 27 | _label.frame = CGRectMake(0, 0, frame.size.width, frame.size.height); 28 | _label.textAlignment = NSTextAlignmentCenter; 29 | [self.contentView addSubview:_label]; 30 | } 31 | return self; 32 | } 33 | @end 34 | 35 | 36 | @interface ViewController () 37 | @property (nonatomic, strong) UICollectionView *collectionView; 38 | @property (nonatomic, strong) NSArray *dataList; 39 | @property (nonatomic, assign) NSInteger currentPage; 40 | @end 41 | 42 | @implementation ViewController 43 | 44 | - (void)viewDidLoad { 45 | [super viewDidLoad]; 46 | // Do any additional setup after loading the view. 47 | _dataList = @[@"🐁", @"🐂", @"🐅", @"🐇", @"🐉", @"🐍", @"🐎", @"🐏", @"🐒", @"🐓", @"🐕", @"🐖"]; 48 | 49 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; 50 | [btn setTitle:@"CompositionalLayout" forState:UIControlStateNormal]; 51 | btn.frame = CGRectMake(self.view.bounds.size.width-160, 44, 160, 44); 52 | [btn addTarget:self action:@selector(compositionalLayout) forControlEvents:UIControlEventTouchUpInside]; 53 | [self.view addSubview:btn]; 54 | 55 | UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new]; 56 | layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; 57 | layout.sectionInset = UIEdgeInsetsMake(0, 38, 0, 38); 58 | layout.minimumLineSpacing = 10; 59 | layout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - 38 * 2, 200); 60 | 61 | _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, 230) collectionViewLayout:layout]; 62 | _collectionView.backgroundColor = [UIColor clearColor]; 63 | [_collectionView registerClass:[EmojiCell class] forCellWithReuseIdentifier:@"EmojiCell"]; 64 | _collectionView.dataSource = self; 65 | _collectionView.delegate = self; 66 | _collectionView.showsHorizontalScrollIndicator = NO; 67 | [self.view addSubview:_collectionView]; 68 | } 69 | 70 | //paging by cell | paging with one cell at a time 71 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView 72 | { 73 | UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout*)self.collectionView.collectionViewLayout; 74 | CGFloat cellWidth = [UIScreen mainScreen].bounds.size.width - layout.sectionInset.left - layout.sectionInset.right; 75 | CGFloat cellPadding = layout.minimumLineSpacing; 76 | self.currentPage = (scrollView.contentOffset.x - cellWidth / 2) / (cellWidth + cellPadding) + 1; 77 | } 78 | 79 | - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset 80 | { 81 | UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout*)self.collectionView.collectionViewLayout; 82 | CGFloat cellWidth = [UIScreen mainScreen].bounds.size.width - layout.sectionInset.left - layout.sectionInset.right; 83 | CGFloat cellPadding = layout.minimumLineSpacing; 84 | NSInteger page = (scrollView.contentOffset.x - cellWidth / 2) / (cellWidth + cellPadding) + 1; 85 | 86 | if (velocity.x > 0) page++; 87 | if (velocity.x < 0) page--; 88 | page = MAX(page, 0); 89 | 90 | //!!!!:此处注掉:会导致快速滑动会跨越多个cell 91 | NSInteger prePage = self.currentPage - 1; 92 | if(prePage > 0 && page < prePage){ 93 | page = prePage; 94 | } else if (page > self.currentPage + 1){ 95 | page = self.currentPage + 1; 96 | } 97 | 98 | self.currentPage = page; 99 | 100 | CGFloat newOffset = page * (cellWidth + cellPadding); 101 | targetContentOffset->x = newOffset; 102 | } 103 | 104 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 105 | { 106 | return self.dataList.count; 107 | } 108 | 109 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 110 | { 111 | EmojiCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"EmojiCell" forIndexPath:indexPath]; 112 | cell.label.text = self.dataList[indexPath.row]; 113 | return cell; 114 | } 115 | 116 | 117 | - (void)compositionalLayout 118 | { 119 | AppStoreCompositionalLayoutController *vc = [AppStoreCompositionalLayoutController new]; 120 | vc.modalPresentationStyle = UIModalPresentationFullScreen; 121 | [self presentViewController:vc animated:YES completion:nil]; 122 | } 123 | @end 124 | -------------------------------------------------------------------------------- /ATPagingByCell/ATPagingByCell/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ATPagingByCell 4 | // 5 | // Created by ApesTalk on 2020/7/13. 6 | // Copyright © 2020 https://github.com/ApesTalk All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | NSString * appDelegateClassName; 14 | @autoreleasepool { 15 | // Setup code that might create autoreleased objects goes here. 16 | appDelegateClassName = NSStringFromClass([AppDelegate class]); 17 | } 18 | return UIApplicationMain(argc, argv, nil, appDelegateClassName); 19 | } 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 ApesTalk 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ATPagingByCell 2 | 3 | A example of perfectly paging by smaller cell (only one cell at a time) not by screen, which like AppStore's banner and Alipay's banner. 4 | 一个使用UICollectionView实现非全屏cell的paging效果,就像AppStore游戏tab顶部banner和支付宝财富tab的财富直通车banner一样的效果(主要是非全屏cell的情况下实现不管是慢速拖拽还是快速拖拽都每次只轮播一个cell)。 5 | 6 | 借助UICollectionView的pagingenabled属性,我们能快速做出漂亮的滑动翻页paging效果,可以满足我们引导页、图片预览、banner等等轮播需求。但当我们的cell宽度不是占满整个UICollectionView的时候,比如我们经常遇到一屏要展示三个cell的效果,而且还要实现一次滑动一个cell的效果。这时候,我们不得不实现``- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset``方法或者自定义UICollectionViewFlowLayout实现``- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity``通过矫正其偏移量来将距离UICollectionView中心点最近的cell居中显示。 7 | 8 | 但是,很显然,单纯这样处理一下,在慢慢拖拽滑动的情况下不会有问题,在快速滑动时会跨cell,也就是一个假的paging效果,如下图所示: 9 | 10 | ![伪paging by cell](https://github.com/ApesTalk/ATPagingByCell/blob/master/emoji0.gif) 11 | 12 | 13 | 如果我们仔细看AppStore的游戏tab顶部banner或者支付宝财富tab的财富直通车banner的paging效果,会发现它们才是真正的paging效果,不管你怎么快速滑动,它每次就是只滑动一个cell,非常的完美。那他们是怎么实现的,为毛我们处理不了这种细节问题???再看看我们目前遇到的问题,只要我们限制不让其每次滑动跨cell就行了,不多解释了,关键代码如下: 14 | 15 | 16 | ``` 17 | //paging by cell | paging with one cell at a time 18 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView 19 | { 20 | UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout*)self.collectionView.collectionViewLayout; 21 | CGFloat cellWidth = [UIScreen mainScreen].bounds.size.width - layout.sectionInset.left - layout.sectionInset.right; 22 | CGFloat cellPadding = layout.minimumLineSpacing; 23 | self.currentPage = (scrollView.contentOffset.x - cellWidth / 2) / (cellWidth + cellPadding) + 1; 24 | } 25 | 26 | - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset 27 | { 28 | UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout*)self.collectionView.collectionViewLayout; 29 | CGFloat cellWidth = [UIScreen mainScreen].bounds.size.width - layout.sectionInset.left - layout.sectionInset.right; 30 | CGFloat cellPadding = layout.minimumLineSpacing; 31 | NSInteger page = (scrollView.contentOffset.x - cellWidth / 2) / (cellWidth + cellPadding) + 1; 32 | 33 | if (velocity.x > 0) page++; 34 | if (velocity.x < 0) page--; 35 | page = MAX(page, 0); 36 | 37 | //!!!!:此处注掉:会导致快速滑动会跨越多个cell 38 | NSInteger prePage = self.currentPage - 1; 39 | if(prePage > 0 && page < prePage){ 40 | page = self.currentPage - 1; 41 | } else if (page > self.currentPage + 1){ 42 | page = self.currentPage + 1; 43 | } 44 | 45 | self.currentPage = page; 46 | 47 | CGFloat newOffset = page * (cellWidth + cellPadding); 48 | targetContentOffset->x = newOffset; 49 | } 50 | ``` 51 | 52 | 最终效果如下: 53 | 54 | ![like AppStore and Alipay](https://github.com/ApesTalk/ATPagingByCell/blob/master/emoji1.gif) 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /emoji0.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApesTalk/ATPagingByCell/c7596de860dc56acecdabe3f51faae82e740c2f8/emoji0.gif -------------------------------------------------------------------------------- /emoji1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApesTalk/ATPagingByCell/c7596de860dc56acecdabe3f51faae82e740c2f8/emoji1.gif --------------------------------------------------------------------------------