├── LPStretchableHeaderView.xcodeproj ├── project.pbxproj └── xcuserdata │ └── ylp.xcuserdatad │ └── xcschemes │ └── LPStretchableHeaderView.xcscheme ├── LPStretchableHeaderView ├── AppDelegate.swift ├── Assets.xcassets │ ├── 123.imageset │ │ ├── 123.jpg │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Extension.swift ├── Info.plist ├── LPStretchableHeaderView.swift └── ViewController.swift ├── LPStretchableHeaderViewTests ├── Info.plist └── LPStretchableHeaderViewTests.swift ├── LPStretchableHeaderViewUITests ├── Info.plist └── LPStretchableHeaderViewUITests.swift ├── README.md └── stretchableView.gif /LPStretchableHeaderView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 454847351F4E76E8009B8BFF /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 454847341F4E76E8009B8BFF /* Extension.swift */; }; 11 | 456EFC001F4D11B800AF6D5D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 456EFBFF1F4D11B800AF6D5D /* AppDelegate.swift */; }; 12 | 456EFC021F4D11B800AF6D5D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 456EFC011F4D11B800AF6D5D /* ViewController.swift */; }; 13 | 456EFC051F4D11B800AF6D5D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 456EFC031F4D11B800AF6D5D /* Main.storyboard */; }; 14 | 456EFC071F4D11B800AF6D5D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 456EFC061F4D11B800AF6D5D /* Assets.xcassets */; }; 15 | 456EFC0A1F4D11B800AF6D5D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 456EFC081F4D11B800AF6D5D /* LaunchScreen.storyboard */; }; 16 | 456EFC151F4D11B800AF6D5D /* LPStretchableHeaderViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 456EFC141F4D11B800AF6D5D /* LPStretchableHeaderViewTests.swift */; }; 17 | 456EFC201F4D11B800AF6D5D /* LPStretchableHeaderViewUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 456EFC1F1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests.swift */; }; 18 | 456EFC2E1F4D2A5400AF6D5D /* LPStretchableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 456EFC2D1F4D2A5400AF6D5D /* LPStretchableHeaderView.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 456EFC111F4D11B800AF6D5D /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 456EFBF41F4D11B800AF6D5D /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 456EFBFB1F4D11B800AF6D5D; 27 | remoteInfo = LPStretchableHeaderView; 28 | }; 29 | 456EFC1C1F4D11B800AF6D5D /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 456EFBF41F4D11B800AF6D5D /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = 456EFBFB1F4D11B800AF6D5D; 34 | remoteInfo = LPStretchableHeaderView; 35 | }; 36 | /* End PBXContainerItemProxy section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | 454847341F4E76E8009B8BFF /* Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = ""; }; 40 | 456EFBFC1F4D11B800AF6D5D /* LPStretchableHeaderView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LPStretchableHeaderView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | 456EFBFF1F4D11B800AF6D5D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 42 | 456EFC011F4D11B800AF6D5D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 43 | 456EFC041F4D11B800AF6D5D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 44 | 456EFC061F4D11B800AF6D5D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 45 | 456EFC091F4D11B800AF6D5D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 46 | 456EFC0B1F4D11B800AF6D5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 47 | 456EFC101F4D11B800AF6D5D /* LPStretchableHeaderViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LPStretchableHeaderViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | 456EFC141F4D11B800AF6D5D /* LPStretchableHeaderViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LPStretchableHeaderViewTests.swift; sourceTree = ""; }; 49 | 456EFC161F4D11B800AF6D5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | 456EFC1B1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LPStretchableHeaderViewUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | 456EFC1F1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LPStretchableHeaderViewUITests.swift; sourceTree = ""; }; 52 | 456EFC211F4D11B800AF6D5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 53 | 456EFC2D1F4D2A5400AF6D5D /* LPStretchableHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LPStretchableHeaderView.swift; sourceTree = ""; }; 54 | /* End PBXFileReference section */ 55 | 56 | /* Begin PBXFrameworksBuildPhase section */ 57 | 456EFBF91F4D11B800AF6D5D /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | ); 62 | runOnlyForDeploymentPostprocessing = 0; 63 | }; 64 | 456EFC0D1F4D11B800AF6D5D /* Frameworks */ = { 65 | isa = PBXFrameworksBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | 456EFC181F4D11B800AF6D5D /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | ); 76 | runOnlyForDeploymentPostprocessing = 0; 77 | }; 78 | /* End PBXFrameworksBuildPhase section */ 79 | 80 | /* Begin PBXGroup section */ 81 | 456EFBF31F4D11B800AF6D5D = { 82 | isa = PBXGroup; 83 | children = ( 84 | 456EFBFE1F4D11B800AF6D5D /* LPStretchableHeaderView */, 85 | 456EFC131F4D11B800AF6D5D /* LPStretchableHeaderViewTests */, 86 | 456EFC1E1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests */, 87 | 456EFBFD1F4D11B800AF6D5D /* Products */, 88 | ); 89 | sourceTree = ""; 90 | }; 91 | 456EFBFD1F4D11B800AF6D5D /* Products */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 456EFBFC1F4D11B800AF6D5D /* LPStretchableHeaderView.app */, 95 | 456EFC101F4D11B800AF6D5D /* LPStretchableHeaderViewTests.xctest */, 96 | 456EFC1B1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests.xctest */, 97 | ); 98 | name = Products; 99 | sourceTree = ""; 100 | }; 101 | 456EFBFE1F4D11B800AF6D5D /* LPStretchableHeaderView */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 456EFBFF1F4D11B800AF6D5D /* AppDelegate.swift */, 105 | 456EFC2D1F4D2A5400AF6D5D /* LPStretchableHeaderView.swift */, 106 | 456EFC011F4D11B800AF6D5D /* ViewController.swift */, 107 | 454847341F4E76E8009B8BFF /* Extension.swift */, 108 | 456EFC031F4D11B800AF6D5D /* Main.storyboard */, 109 | 456EFC061F4D11B800AF6D5D /* Assets.xcassets */, 110 | 456EFC081F4D11B800AF6D5D /* LaunchScreen.storyboard */, 111 | 456EFC0B1F4D11B800AF6D5D /* Info.plist */, 112 | ); 113 | path = LPStretchableHeaderView; 114 | sourceTree = ""; 115 | }; 116 | 456EFC131F4D11B800AF6D5D /* LPStretchableHeaderViewTests */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 456EFC141F4D11B800AF6D5D /* LPStretchableHeaderViewTests.swift */, 120 | 456EFC161F4D11B800AF6D5D /* Info.plist */, 121 | ); 122 | path = LPStretchableHeaderViewTests; 123 | sourceTree = ""; 124 | }; 125 | 456EFC1E1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 456EFC1F1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests.swift */, 129 | 456EFC211F4D11B800AF6D5D /* Info.plist */, 130 | ); 131 | path = LPStretchableHeaderViewUITests; 132 | sourceTree = ""; 133 | }; 134 | /* End PBXGroup section */ 135 | 136 | /* Begin PBXNativeTarget section */ 137 | 456EFBFB1F4D11B800AF6D5D /* LPStretchableHeaderView */ = { 138 | isa = PBXNativeTarget; 139 | buildConfigurationList = 456EFC241F4D11B800AF6D5D /* Build configuration list for PBXNativeTarget "LPStretchableHeaderView" */; 140 | buildPhases = ( 141 | 456EFBF81F4D11B800AF6D5D /* Sources */, 142 | 456EFBF91F4D11B800AF6D5D /* Frameworks */, 143 | 456EFBFA1F4D11B800AF6D5D /* Resources */, 144 | ); 145 | buildRules = ( 146 | ); 147 | dependencies = ( 148 | ); 149 | name = LPStretchableHeaderView; 150 | productName = LPStretchableHeaderView; 151 | productReference = 456EFBFC1F4D11B800AF6D5D /* LPStretchableHeaderView.app */; 152 | productType = "com.apple.product-type.application"; 153 | }; 154 | 456EFC0F1F4D11B800AF6D5D /* LPStretchableHeaderViewTests */ = { 155 | isa = PBXNativeTarget; 156 | buildConfigurationList = 456EFC271F4D11B800AF6D5D /* Build configuration list for PBXNativeTarget "LPStretchableHeaderViewTests" */; 157 | buildPhases = ( 158 | 456EFC0C1F4D11B800AF6D5D /* Sources */, 159 | 456EFC0D1F4D11B800AF6D5D /* Frameworks */, 160 | 456EFC0E1F4D11B800AF6D5D /* Resources */, 161 | ); 162 | buildRules = ( 163 | ); 164 | dependencies = ( 165 | 456EFC121F4D11B800AF6D5D /* PBXTargetDependency */, 166 | ); 167 | name = LPStretchableHeaderViewTests; 168 | productName = LPStretchableHeaderViewTests; 169 | productReference = 456EFC101F4D11B800AF6D5D /* LPStretchableHeaderViewTests.xctest */; 170 | productType = "com.apple.product-type.bundle.unit-test"; 171 | }; 172 | 456EFC1A1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests */ = { 173 | isa = PBXNativeTarget; 174 | buildConfigurationList = 456EFC2A1F4D11B800AF6D5D /* Build configuration list for PBXNativeTarget "LPStretchableHeaderViewUITests" */; 175 | buildPhases = ( 176 | 456EFC171F4D11B800AF6D5D /* Sources */, 177 | 456EFC181F4D11B800AF6D5D /* Frameworks */, 178 | 456EFC191F4D11B800AF6D5D /* Resources */, 179 | ); 180 | buildRules = ( 181 | ); 182 | dependencies = ( 183 | 456EFC1D1F4D11B800AF6D5D /* PBXTargetDependency */, 184 | ); 185 | name = LPStretchableHeaderViewUITests; 186 | productName = LPStretchableHeaderViewUITests; 187 | productReference = 456EFC1B1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests.xctest */; 188 | productType = "com.apple.product-type.bundle.ui-testing"; 189 | }; 190 | /* End PBXNativeTarget section */ 191 | 192 | /* Begin PBXProject section */ 193 | 456EFBF41F4D11B800AF6D5D /* Project object */ = { 194 | isa = PBXProject; 195 | attributes = { 196 | LastSwiftUpdateCheck = 0830; 197 | LastUpgradeCheck = 0830; 198 | ORGANIZATIONNAME = Tony; 199 | TargetAttributes = { 200 | 456EFBFB1F4D11B800AF6D5D = { 201 | CreatedOnToolsVersion = 8.3.3; 202 | DevelopmentTeam = RWKH7R4DZR; 203 | LastSwiftMigration = 0830; 204 | ProvisioningStyle = Automatic; 205 | }; 206 | 456EFC0F1F4D11B800AF6D5D = { 207 | CreatedOnToolsVersion = 8.3.3; 208 | DevelopmentTeam = RWKH7R4DZR; 209 | ProvisioningStyle = Automatic; 210 | TestTargetID = 456EFBFB1F4D11B800AF6D5D; 211 | }; 212 | 456EFC1A1F4D11B800AF6D5D = { 213 | CreatedOnToolsVersion = 8.3.3; 214 | DevelopmentTeam = RWKH7R4DZR; 215 | ProvisioningStyle = Automatic; 216 | TestTargetID = 456EFBFB1F4D11B800AF6D5D; 217 | }; 218 | }; 219 | }; 220 | buildConfigurationList = 456EFBF71F4D11B800AF6D5D /* Build configuration list for PBXProject "LPStretchableHeaderView" */; 221 | compatibilityVersion = "Xcode 3.2"; 222 | developmentRegion = English; 223 | hasScannedForEncodings = 0; 224 | knownRegions = ( 225 | en, 226 | Base, 227 | ); 228 | mainGroup = 456EFBF31F4D11B800AF6D5D; 229 | productRefGroup = 456EFBFD1F4D11B800AF6D5D /* Products */; 230 | projectDirPath = ""; 231 | projectRoot = ""; 232 | targets = ( 233 | 456EFBFB1F4D11B800AF6D5D /* LPStretchableHeaderView */, 234 | 456EFC0F1F4D11B800AF6D5D /* LPStretchableHeaderViewTests */, 235 | 456EFC1A1F4D11B800AF6D5D /* LPStretchableHeaderViewUITests */, 236 | ); 237 | }; 238 | /* End PBXProject section */ 239 | 240 | /* Begin PBXResourcesBuildPhase section */ 241 | 456EFBFA1F4D11B800AF6D5D /* Resources */ = { 242 | isa = PBXResourcesBuildPhase; 243 | buildActionMask = 2147483647; 244 | files = ( 245 | 456EFC0A1F4D11B800AF6D5D /* LaunchScreen.storyboard in Resources */, 246 | 456EFC071F4D11B800AF6D5D /* Assets.xcassets in Resources */, 247 | 456EFC051F4D11B800AF6D5D /* Main.storyboard in Resources */, 248 | ); 249 | runOnlyForDeploymentPostprocessing = 0; 250 | }; 251 | 456EFC0E1F4D11B800AF6D5D /* Resources */ = { 252 | isa = PBXResourcesBuildPhase; 253 | buildActionMask = 2147483647; 254 | files = ( 255 | ); 256 | runOnlyForDeploymentPostprocessing = 0; 257 | }; 258 | 456EFC191F4D11B800AF6D5D /* Resources */ = { 259 | isa = PBXResourcesBuildPhase; 260 | buildActionMask = 2147483647; 261 | files = ( 262 | ); 263 | runOnlyForDeploymentPostprocessing = 0; 264 | }; 265 | /* End PBXResourcesBuildPhase section */ 266 | 267 | /* Begin PBXSourcesBuildPhase section */ 268 | 456EFBF81F4D11B800AF6D5D /* Sources */ = { 269 | isa = PBXSourcesBuildPhase; 270 | buildActionMask = 2147483647; 271 | files = ( 272 | 456EFC021F4D11B800AF6D5D /* ViewController.swift in Sources */, 273 | 456EFC001F4D11B800AF6D5D /* AppDelegate.swift in Sources */, 274 | 456EFC2E1F4D2A5400AF6D5D /* LPStretchableHeaderView.swift in Sources */, 275 | 454847351F4E76E8009B8BFF /* Extension.swift in Sources */, 276 | ); 277 | runOnlyForDeploymentPostprocessing = 0; 278 | }; 279 | 456EFC0C1F4D11B800AF6D5D /* Sources */ = { 280 | isa = PBXSourcesBuildPhase; 281 | buildActionMask = 2147483647; 282 | files = ( 283 | 456EFC151F4D11B800AF6D5D /* LPStretchableHeaderViewTests.swift in Sources */, 284 | ); 285 | runOnlyForDeploymentPostprocessing = 0; 286 | }; 287 | 456EFC171F4D11B800AF6D5D /* Sources */ = { 288 | isa = PBXSourcesBuildPhase; 289 | buildActionMask = 2147483647; 290 | files = ( 291 | 456EFC201F4D11B800AF6D5D /* LPStretchableHeaderViewUITests.swift in Sources */, 292 | ); 293 | runOnlyForDeploymentPostprocessing = 0; 294 | }; 295 | /* End PBXSourcesBuildPhase section */ 296 | 297 | /* Begin PBXTargetDependency section */ 298 | 456EFC121F4D11B800AF6D5D /* PBXTargetDependency */ = { 299 | isa = PBXTargetDependency; 300 | target = 456EFBFB1F4D11B800AF6D5D /* LPStretchableHeaderView */; 301 | targetProxy = 456EFC111F4D11B800AF6D5D /* PBXContainerItemProxy */; 302 | }; 303 | 456EFC1D1F4D11B800AF6D5D /* PBXTargetDependency */ = { 304 | isa = PBXTargetDependency; 305 | target = 456EFBFB1F4D11B800AF6D5D /* LPStretchableHeaderView */; 306 | targetProxy = 456EFC1C1F4D11B800AF6D5D /* PBXContainerItemProxy */; 307 | }; 308 | /* End PBXTargetDependency section */ 309 | 310 | /* Begin PBXVariantGroup section */ 311 | 456EFC031F4D11B800AF6D5D /* Main.storyboard */ = { 312 | isa = PBXVariantGroup; 313 | children = ( 314 | 456EFC041F4D11B800AF6D5D /* Base */, 315 | ); 316 | name = Main.storyboard; 317 | sourceTree = ""; 318 | }; 319 | 456EFC081F4D11B800AF6D5D /* LaunchScreen.storyboard */ = { 320 | isa = PBXVariantGroup; 321 | children = ( 322 | 456EFC091F4D11B800AF6D5D /* Base */, 323 | ); 324 | name = LaunchScreen.storyboard; 325 | sourceTree = ""; 326 | }; 327 | /* End PBXVariantGroup section */ 328 | 329 | /* Begin XCBuildConfiguration section */ 330 | 456EFC221F4D11B800AF6D5D /* Debug */ = { 331 | isa = XCBuildConfiguration; 332 | buildSettings = { 333 | ALWAYS_SEARCH_USER_PATHS = NO; 334 | CLANG_ANALYZER_NONNULL = YES; 335 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 336 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 337 | CLANG_CXX_LIBRARY = "libc++"; 338 | CLANG_ENABLE_MODULES = YES; 339 | CLANG_ENABLE_OBJC_ARC = YES; 340 | CLANG_WARN_BOOL_CONVERSION = YES; 341 | CLANG_WARN_CONSTANT_CONVERSION = YES; 342 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 343 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 344 | CLANG_WARN_EMPTY_BODY = YES; 345 | CLANG_WARN_ENUM_CONVERSION = YES; 346 | CLANG_WARN_INFINITE_RECURSION = YES; 347 | CLANG_WARN_INT_CONVERSION = YES; 348 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 349 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 350 | CLANG_WARN_UNREACHABLE_CODE = YES; 351 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 352 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 353 | COPY_PHASE_STRIP = NO; 354 | DEBUG_INFORMATION_FORMAT = dwarf; 355 | ENABLE_STRICT_OBJC_MSGSEND = YES; 356 | ENABLE_TESTABILITY = YES; 357 | GCC_C_LANGUAGE_STANDARD = gnu99; 358 | GCC_DYNAMIC_NO_PIC = NO; 359 | GCC_NO_COMMON_BLOCKS = YES; 360 | GCC_OPTIMIZATION_LEVEL = 0; 361 | GCC_PREPROCESSOR_DEFINITIONS = ( 362 | "DEBUG=1", 363 | "$(inherited)", 364 | ); 365 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 366 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 367 | GCC_WARN_UNDECLARED_SELECTOR = YES; 368 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 369 | GCC_WARN_UNUSED_FUNCTION = YES; 370 | GCC_WARN_UNUSED_VARIABLE = YES; 371 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 372 | MTL_ENABLE_DEBUG_INFO = YES; 373 | ONLY_ACTIVE_ARCH = YES; 374 | SDKROOT = iphoneos; 375 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 376 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 377 | }; 378 | name = Debug; 379 | }; 380 | 456EFC231F4D11B800AF6D5D /* Release */ = { 381 | isa = XCBuildConfiguration; 382 | buildSettings = { 383 | ALWAYS_SEARCH_USER_PATHS = NO; 384 | CLANG_ANALYZER_NONNULL = YES; 385 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 386 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 387 | CLANG_CXX_LIBRARY = "libc++"; 388 | CLANG_ENABLE_MODULES = YES; 389 | CLANG_ENABLE_OBJC_ARC = YES; 390 | CLANG_WARN_BOOL_CONVERSION = YES; 391 | CLANG_WARN_CONSTANT_CONVERSION = YES; 392 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 393 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 394 | CLANG_WARN_EMPTY_BODY = YES; 395 | CLANG_WARN_ENUM_CONVERSION = YES; 396 | CLANG_WARN_INFINITE_RECURSION = YES; 397 | CLANG_WARN_INT_CONVERSION = YES; 398 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 399 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 400 | CLANG_WARN_UNREACHABLE_CODE = YES; 401 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 402 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 403 | COPY_PHASE_STRIP = NO; 404 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 405 | ENABLE_NS_ASSERTIONS = NO; 406 | ENABLE_STRICT_OBJC_MSGSEND = YES; 407 | GCC_C_LANGUAGE_STANDARD = gnu99; 408 | GCC_NO_COMMON_BLOCKS = YES; 409 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 410 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 411 | GCC_WARN_UNDECLARED_SELECTOR = YES; 412 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 413 | GCC_WARN_UNUSED_FUNCTION = YES; 414 | GCC_WARN_UNUSED_VARIABLE = YES; 415 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 416 | MTL_ENABLE_DEBUG_INFO = NO; 417 | SDKROOT = iphoneos; 418 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 419 | VALIDATE_PRODUCT = YES; 420 | }; 421 | name = Release; 422 | }; 423 | 456EFC251F4D11B800AF6D5D /* Debug */ = { 424 | isa = XCBuildConfiguration; 425 | buildSettings = { 426 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 427 | CLANG_ENABLE_MODULES = YES; 428 | DEVELOPMENT_TEAM = RWKH7R4DZR; 429 | INFOPLIST_FILE = LPStretchableHeaderView/Info.plist; 430 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 431 | PRODUCT_BUNDLE_IDENTIFIER = com.Tony.ylp.LPStretchableHeaderView; 432 | PRODUCT_NAME = "$(TARGET_NAME)"; 433 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 434 | SWIFT_VERSION = 3.0; 435 | }; 436 | name = Debug; 437 | }; 438 | 456EFC261F4D11B800AF6D5D /* Release */ = { 439 | isa = XCBuildConfiguration; 440 | buildSettings = { 441 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 442 | CLANG_ENABLE_MODULES = YES; 443 | DEVELOPMENT_TEAM = RWKH7R4DZR; 444 | INFOPLIST_FILE = LPStretchableHeaderView/Info.plist; 445 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 446 | PRODUCT_BUNDLE_IDENTIFIER = com.Tony.ylp.LPStretchableHeaderView; 447 | PRODUCT_NAME = "$(TARGET_NAME)"; 448 | SWIFT_VERSION = 3.0; 449 | }; 450 | name = Release; 451 | }; 452 | 456EFC281F4D11B800AF6D5D /* Debug */ = { 453 | isa = XCBuildConfiguration; 454 | buildSettings = { 455 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 456 | BUNDLE_LOADER = "$(TEST_HOST)"; 457 | DEVELOPMENT_TEAM = RWKH7R4DZR; 458 | INFOPLIST_FILE = LPStretchableHeaderViewTests/Info.plist; 459 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 460 | PRODUCT_BUNDLE_IDENTIFIER = com.Tony.ylp.LPStretchableHeaderViewTests; 461 | PRODUCT_NAME = "$(TARGET_NAME)"; 462 | SWIFT_VERSION = 3.0; 463 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LPStretchableHeaderView.app/LPStretchableHeaderView"; 464 | }; 465 | name = Debug; 466 | }; 467 | 456EFC291F4D11B800AF6D5D /* Release */ = { 468 | isa = XCBuildConfiguration; 469 | buildSettings = { 470 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 471 | BUNDLE_LOADER = "$(TEST_HOST)"; 472 | DEVELOPMENT_TEAM = RWKH7R4DZR; 473 | INFOPLIST_FILE = LPStretchableHeaderViewTests/Info.plist; 474 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 475 | PRODUCT_BUNDLE_IDENTIFIER = com.Tony.ylp.LPStretchableHeaderViewTests; 476 | PRODUCT_NAME = "$(TARGET_NAME)"; 477 | SWIFT_VERSION = 3.0; 478 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LPStretchableHeaderView.app/LPStretchableHeaderView"; 479 | }; 480 | name = Release; 481 | }; 482 | 456EFC2B1F4D11B800AF6D5D /* Debug */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 486 | DEVELOPMENT_TEAM = RWKH7R4DZR; 487 | INFOPLIST_FILE = LPStretchableHeaderViewUITests/Info.plist; 488 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 489 | PRODUCT_BUNDLE_IDENTIFIER = com.Tony.ylp.LPStretchableHeaderViewUITests; 490 | PRODUCT_NAME = "$(TARGET_NAME)"; 491 | SWIFT_VERSION = 3.0; 492 | TEST_TARGET_NAME = LPStretchableHeaderView; 493 | }; 494 | name = Debug; 495 | }; 496 | 456EFC2C1F4D11B800AF6D5D /* Release */ = { 497 | isa = XCBuildConfiguration; 498 | buildSettings = { 499 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 500 | DEVELOPMENT_TEAM = RWKH7R4DZR; 501 | INFOPLIST_FILE = LPStretchableHeaderViewUITests/Info.plist; 502 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 503 | PRODUCT_BUNDLE_IDENTIFIER = com.Tony.ylp.LPStretchableHeaderViewUITests; 504 | PRODUCT_NAME = "$(TARGET_NAME)"; 505 | SWIFT_VERSION = 3.0; 506 | TEST_TARGET_NAME = LPStretchableHeaderView; 507 | }; 508 | name = Release; 509 | }; 510 | /* End XCBuildConfiguration section */ 511 | 512 | /* Begin XCConfigurationList section */ 513 | 456EFBF71F4D11B800AF6D5D /* Build configuration list for PBXProject "LPStretchableHeaderView" */ = { 514 | isa = XCConfigurationList; 515 | buildConfigurations = ( 516 | 456EFC221F4D11B800AF6D5D /* Debug */, 517 | 456EFC231F4D11B800AF6D5D /* Release */, 518 | ); 519 | defaultConfigurationIsVisible = 0; 520 | defaultConfigurationName = Release; 521 | }; 522 | 456EFC241F4D11B800AF6D5D /* Build configuration list for PBXNativeTarget "LPStretchableHeaderView" */ = { 523 | isa = XCConfigurationList; 524 | buildConfigurations = ( 525 | 456EFC251F4D11B800AF6D5D /* Debug */, 526 | 456EFC261F4D11B800AF6D5D /* Release */, 527 | ); 528 | defaultConfigurationIsVisible = 0; 529 | defaultConfigurationName = Release; 530 | }; 531 | 456EFC271F4D11B800AF6D5D /* Build configuration list for PBXNativeTarget "LPStretchableHeaderViewTests" */ = { 532 | isa = XCConfigurationList; 533 | buildConfigurations = ( 534 | 456EFC281F4D11B800AF6D5D /* Debug */, 535 | 456EFC291F4D11B800AF6D5D /* Release */, 536 | ); 537 | defaultConfigurationIsVisible = 0; 538 | defaultConfigurationName = Release; 539 | }; 540 | 456EFC2A1F4D11B800AF6D5D /* Build configuration list for PBXNativeTarget "LPStretchableHeaderViewUITests" */ = { 541 | isa = XCConfigurationList; 542 | buildConfigurations = ( 543 | 456EFC2B1F4D11B800AF6D5D /* Debug */, 544 | 456EFC2C1F4D11B800AF6D5D /* Release */, 545 | ); 546 | defaultConfigurationIsVisible = 0; 547 | defaultConfigurationName = Release; 548 | }; 549 | /* End XCConfigurationList section */ 550 | }; 551 | rootObject = 456EFBF41F4D11B800AF6D5D /* Project object */; 552 | } 553 | -------------------------------------------------------------------------------- /LPStretchableHeaderView.xcodeproj/xcuserdata/ylp.xcuserdatad/xcschemes/LPStretchableHeaderView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /LPStretchableHeaderView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LPStretchableHeaderView 4 | // 5 | // Created by Tony on 2017/8/23. 6 | // Copyright © 2017年 Tony. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /LPStretchableHeaderView/Assets.xcassets/123.imageset/123.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/splsylp/LPStretchableHeaderView/df45390929c2c09253a554025226b43dc13076f1/LPStretchableHeaderView/Assets.xcassets/123.imageset/123.jpg -------------------------------------------------------------------------------- /LPStretchableHeaderView/Assets.xcassets/123.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "123.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /LPStretchableHeaderView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | } 43 | ], 44 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /LPStretchableHeaderView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /LPStretchableHeaderView/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LPStretchableHeaderView/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 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /LPStretchableHeaderView/Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Extension.swift 3 | // LPStretchableHeaderView 4 | // 5 | // Created by Tony on 2017/8/24. 6 | // Copyright © 2017年 Tony. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | // 屏幕宽度 12 | let SCREEN_HEIGHT = UIScreen.main.bounds.size.height 13 | // 屏幕高度 14 | let SCREEN_WIDTH = UIScreen.main.bounds.size.width 15 | 16 | 17 | extension UIView { 18 | 19 | public var x: CGFloat { 20 | get { 21 | return self.frame.origin.x 22 | } 23 | set { 24 | var frame = self.frame 25 | frame.origin.x = newValue 26 | self.frame = frame 27 | } 28 | } 29 | 30 | public var y: CGFloat{ 31 | get { 32 | return self.frame.origin.y 33 | } 34 | set { 35 | var frame = self.frame 36 | frame.origin.y = newValue 37 | self.frame = frame 38 | } 39 | } 40 | 41 | /** 宽 */ 42 | public var width: CGFloat{ 43 | get { 44 | return self.frame.size.width 45 | } 46 | set { 47 | var frame = self.frame 48 | frame.size.width = newValue 49 | self.frame = frame 50 | } 51 | } 52 | 53 | /** 高 */ 54 | public var height: CGFloat{ 55 | get { 56 | return self.frame.size.height 57 | } 58 | set { 59 | var frame = self.frame 60 | frame.size.height = newValue 61 | self.frame = frame 62 | } 63 | } 64 | 65 | /** 下 */ 66 | public var bottom: CGFloat{ 67 | get { 68 | return self.frame.origin.y + self.frame.size.height 69 | } 70 | 71 | set { 72 | var frame = self.frame 73 | frame.origin.y = newValue - self.frame.size.height 74 | self.frame = frame 75 | } 76 | } 77 | 78 | /** 右 */ 79 | public var right: CGFloat{ 80 | get { 81 | return self.frame.origin.x + self.frame.size.width 82 | } 83 | 84 | set { 85 | var frame = self.frame 86 | frame.origin.x = newValue - self.frame.size.width 87 | self.frame = frame 88 | } 89 | } 90 | 91 | /** 尺寸 */ 92 | public var size: CGSize{ 93 | get { 94 | return self.frame.size 95 | } 96 | 97 | set { 98 | var frame = self.frame 99 | frame.size = newValue 100 | self.frame = frame 101 | } 102 | } 103 | 104 | /** 竖直中心对齐 */ 105 | public var centerX: CGFloat{ 106 | get { 107 | return self.center.x 108 | } 109 | 110 | set { 111 | var center = self.center 112 | center.x = newValue 113 | self.center = center 114 | } 115 | } 116 | 117 | /** 水平中心对齐 */ 118 | public var centerY: CGFloat{ 119 | get { 120 | return self.center.y 121 | } 122 | 123 | set { 124 | var center = self.center 125 | center.y = newValue 126 | self.center = center 127 | } 128 | } 129 | } 130 | 131 | 132 | extension UIColor { 133 | 134 | class var Main: UIColor { 135 | return UIColor(red: 74 / 255.0, green: 163 / 255.0, blue: 243 / 255.0, alpha: 1.0) 136 | } 137 | 138 | class var Gray: UIColor { 139 | return UIColor(red: 242 / 255.0, green: 243 / 255.0, blue: 248 / 255.0, alpha: 1.0) 140 | } 141 | 142 | class func RGB_COLOR(_ r:CGFloat, g:CGFloat, b:CGFloat, alpha:CGFloat) -> UIColor { 143 | return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: alpha) 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /LPStretchableHeaderView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /LPStretchableHeaderView/LPStretchableHeaderView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LPStretchableHeaderView.swift 3 | // LPStretchableHeaderView 4 | // 5 | // Created by Tony on 2017/8/23. 6 | // Copyright © 2017年 Tony. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class LPStretchableHeaderView: NSObject { 12 | 13 | private var stretchView = UIView() 14 | private var imageRatio: CGFloat 15 | private var originFrame = CGRect() 16 | 17 | public init(stretchableView: UIView) { 18 | 19 | stretchView = stretchableView 20 | originFrame = stretchableView.frame 21 | imageRatio = stretchableView.bounds.height / stretchableView.bounds.width 22 | } 23 | 24 | public func scrollViewDidScroll(_ scrollView: UIScrollView) { 25 | 26 | let yOffset = scrollView.contentOffset.y 27 | if yOffset > 0 { // 往上移动 28 | var frame = originFrame 29 | frame.origin.y = originFrame.origin.y - yOffset 30 | stretchView.frame = frame 31 | } else { // 往下移动 32 | var frame = originFrame 33 | frame.size.height = originFrame.size.height - yOffset 34 | frame.size.width = frame.size.height / imageRatio 35 | frame.origin.x = originFrame.origin.x - (frame.size.width - originFrame.size.width) * 0.5 36 | stretchView.frame = frame 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LPStretchableHeaderView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // LPStretchableHeaderView 4 | // 5 | // Created by Tony on 2017/8/23. 6 | // Copyright © 2017年 Tony. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 12 | 13 | var bgImageView: UIImageView! 14 | var navView: UIView! 15 | var stretchableView: LPStretchableHeaderView! 16 | 17 | var headerHeight: CGFloat = 0 18 | 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | 23 | bgImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_WIDTH * 0.75)) 24 | bgImageView.image = UIImage(named: "123") 25 | view.addSubview(bgImageView) 26 | 27 | let tableView = UITableView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT)) 28 | tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") 29 | tableView.dataSource = self 30 | tableView.delegate = self 31 | tableView.showsVerticalScrollIndicator = false 32 | tableView.backgroundColor = UIColor.clear 33 | view.addSubview(tableView) 34 | 35 | let headerView = UIView(frame: bgImageView.bounds) 36 | headerView.height -= 80 // 对背景图片进行一部分的遮盖(可选,,可以不遮盖。。。) 37 | headerHeight = headerView.height 38 | tableView.tableHeaderView = headerView 39 | 40 | let nameLabel = UILabel(frame: CGRect(x: 0, y: 150, width: bgImageView.width, height: 40)) 41 | nameLabel.text = "哈哈哈😆" 42 | nameLabel.textAlignment = .center 43 | nameLabel.textColor = UIColor.white 44 | headerView.addSubview(nameLabel) 45 | 46 | makeNavView() 47 | 48 | stretchableView = LPStretchableHeaderView(stretchableView: bgImageView) 49 | } 50 | 51 | // 导航栏 52 | func makeNavView() { 53 | 54 | navView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 64)) 55 | view.addSubview(navView) 56 | 57 | let titleLabel = UILabel(frame: navView.bounds) 58 | titleLabel.text = "导航栏标题" 59 | titleLabel.textColor = UIColor.white 60 | titleLabel.textAlignment = .center 61 | navView.addSubview(titleLabel) 62 | } 63 | 64 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 65 | return 20 66 | } 67 | 68 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 69 | 70 | let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 71 | cell.textLabel?.text = "000" 72 | return cell 73 | } 74 | 75 | func scrollViewDidScroll(_ scrollView: UIScrollView) { 76 | 77 | // 导航栏设置 78 | let yOffset = scrollView.contentOffset.y 79 | if yOffset < (headerHeight - navView.height) { 80 | let alpha = yOffset / (headerHeight - navView.height) 81 | navView.backgroundColor = UIColor.RGB_COLOR(74, g: 163, b: 243, alpha: alpha) 82 | } else { 83 | navView.backgroundColor = UIColor.RGB_COLOR(74, g: 163, b: 243, alpha: 1) 84 | } 85 | 86 | stretchableView.scrollViewDidScroll(scrollView) 87 | } 88 | 89 | } 90 | 91 | -------------------------------------------------------------------------------- /LPStretchableHeaderViewTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LPStretchableHeaderViewTests/LPStretchableHeaderViewTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LPStretchableHeaderViewTests.swift 3 | // LPStretchableHeaderViewTests 4 | // 5 | // Created by Tony on 2017/8/23. 6 | // Copyright © 2017年 Tony. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import LPStretchableHeaderView 11 | 12 | class LPStretchableHeaderViewTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /LPStretchableHeaderViewUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LPStretchableHeaderViewUITests/LPStretchableHeaderViewUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LPStretchableHeaderViewUITests.swift 3 | // LPStretchableHeaderViewUITests 4 | // 5 | // Created by Tony on 2017/8/23. 6 | // Copyright © 2017年 Tony. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class LPStretchableHeaderViewUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LPStretchableHeaderView 2 | #### 两行代码实现tableView头部视图拉伸放大效果 3 | 4 | ![image](https://github.com/splsylp/LPStretchableHeaderView/blob/master/stretchableView.gif ) 5 | 6 | #### [实现原理解析](http://www.jianshu.com/p/1b3788dfa4ea) 7 | 8 | 9 | ##### 使用 10 | ###### 1.初始化调用 11 | ```Swift 12 | stretchableView = LPStretchableHeaderView(stretchableView: bgImageView) 13 | ``` 14 | ###### 2.代理方法实现: 15 | ```Swift 16 | func scrollViewDidScroll(_ scrollView: UIScrollView) { 17 | stretchableView.scrollViewDidScroll(scrollView) 18 | } 19 | ``` 20 | --- 21 | ### 您的star,是对我最大的鼓励与支持~ 22 | -------------------------------------------------------------------------------- /stretchableView.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/splsylp/LPStretchableHeaderView/df45390929c2c09253a554025226b43dc13076f1/stretchableView.gif --------------------------------------------------------------------------------