├── .gitignore ├── APDynamicHeaderTableViewController.podspec ├── APDynamicHeaderTableViewController.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── aaronpang.xcuserdatad │ └── xcschemes │ ├── APDynamicHeaderTableViewController.xcscheme │ └── xcschememanagement.plist ├── APDynamicHeaderTableViewController.xcworkspace └── contents.xcworkspacedata ├── APDynamicHeaderTableViewController ├── APDynamicHeaderTableViewController.swift ├── APDynamicHeaderView.swift ├── AppDelegate.swift ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── Info.plist └── SampleViewController.swift ├── APDynamicHeaderTableViewControllerTests ├── APDynamicHeaderTableViewControllerTests.swift └── Info.plist ├── Gifs ├── one.gif └── two.gif ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "APDynamicHeaderTableViewController" 3 | s.version = "0.1.1" 4 | s.summary = "A simple table view controller with a header view made as a recreation of the Instagram header." 5 | s.homepage = "https://github.com/aaronpang/APDynamicHeaderTableViewController" 6 | 7 | s.license = { :type => 'MIT', :file => 'LICENSE' } 8 | s.author = { "Aaron Pang" => "pang.aaron56@gmail.com" } 9 | s.source = { 10 | :git => "https://github.com/aaronpang/APDynamicHeaderTableViewController.git", 11 | :tag => "0.1.1" 12 | } 13 | 14 | s.platform = :ios, '8.0' 15 | s.source_files = 'APDynamicHeaderTableViewController/{APDynamicHeaderTableViewController,APDynamicHeaderView}.swift' 16 | s.requires_arc = true 17 | end -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E30162681AF1BBA100730D27 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E30162671AF1BBA100730D27 /* AppDelegate.swift */; }; 11 | E301626F1AF1BBA100730D27 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E301626E1AF1BBA100730D27 /* Images.xcassets */; }; 12 | E301627E1AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E301627D1AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests.swift */; }; 13 | E30162891AF1BBB000730D27 /* APDynamicHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E30162871AF1BBB000730D27 /* APDynamicHeaderView.swift */; }; 14 | E301628A1AF1BBB000730D27 /* APDynamicHeaderTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E30162881AF1BBB000730D27 /* APDynamicHeaderTableViewController.swift */; }; 15 | E301628C1AF1BBB700730D27 /* SampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E301628B1AF1BBB700730D27 /* SampleViewController.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXContainerItemProxy section */ 19 | E30162781AF1BBA200730D27 /* PBXContainerItemProxy */ = { 20 | isa = PBXContainerItemProxy; 21 | containerPortal = E301625A1AF1BBA100730D27 /* Project object */; 22 | proxyType = 1; 23 | remoteGlobalIDString = E30162611AF1BBA100730D27; 24 | remoteInfo = APDynamicHeaderTableViewController; 25 | }; 26 | /* End PBXContainerItemProxy section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | E30162621AF1BBA100730D27 /* APDynamicHeaderTableViewController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = APDynamicHeaderTableViewController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | E30162661AF1BBA100730D27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31 | E30162671AF1BBA100730D27 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = APDynamicHeaderTableViewController/AppDelegate.swift; sourceTree = ""; }; 32 | E301626E1AF1BBA100730D27 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 33 | E30162771AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = APDynamicHeaderTableViewControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | E301627C1AF1BBA200730D27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | E301627D1AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APDynamicHeaderTableViewControllerTests.swift; sourceTree = ""; }; 36 | E30162871AF1BBB000730D27 /* APDynamicHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APDynamicHeaderView.swift; sourceTree = ""; }; 37 | E30162881AF1BBB000730D27 /* APDynamicHeaderTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APDynamicHeaderTableViewController.swift; sourceTree = ""; }; 38 | E301628B1AF1BBB700730D27 /* SampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SampleViewController.swift; path = APDynamicHeaderTableViewController/SampleViewController.swift; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | E301625F1AF1BBA100730D27 /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | ); 47 | runOnlyForDeploymentPostprocessing = 0; 48 | }; 49 | E30162741AF1BBA200730D27 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | /* End PBXFrameworksBuildPhase section */ 57 | 58 | /* Begin PBXGroup section */ 59 | E30162591AF1BBA100730D27 = { 60 | isa = PBXGroup; 61 | children = ( 62 | E301628B1AF1BBB700730D27 /* SampleViewController.swift */, 63 | E30162671AF1BBA100730D27 /* AppDelegate.swift */, 64 | E30162641AF1BBA100730D27 /* APDynamicHeaderTableViewController */, 65 | E301627A1AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests */, 66 | E30162631AF1BBA100730D27 /* Products */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | E30162631AF1BBA100730D27 /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | E30162621AF1BBA100730D27 /* APDynamicHeaderTableViewController.app */, 74 | E30162771AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests.xctest */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | E30162641AF1BBA100730D27 /* APDynamicHeaderTableViewController */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | E30162871AF1BBB000730D27 /* APDynamicHeaderView.swift */, 83 | E30162881AF1BBB000730D27 /* APDynamicHeaderTableViewController.swift */, 84 | E301626E1AF1BBA100730D27 /* Images.xcassets */, 85 | E30162651AF1BBA100730D27 /* Supporting Files */, 86 | ); 87 | path = APDynamicHeaderTableViewController; 88 | sourceTree = ""; 89 | }; 90 | E30162651AF1BBA100730D27 /* Supporting Files */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | E30162661AF1BBA100730D27 /* Info.plist */, 94 | ); 95 | name = "Supporting Files"; 96 | sourceTree = ""; 97 | }; 98 | E301627A1AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | E301627D1AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests.swift */, 102 | E301627B1AF1BBA200730D27 /* Supporting Files */, 103 | ); 104 | path = APDynamicHeaderTableViewControllerTests; 105 | sourceTree = ""; 106 | }; 107 | E301627B1AF1BBA200730D27 /* Supporting Files */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | E301627C1AF1BBA200730D27 /* Info.plist */, 111 | ); 112 | name = "Supporting Files"; 113 | sourceTree = ""; 114 | }; 115 | /* End PBXGroup section */ 116 | 117 | /* Begin PBXNativeTarget section */ 118 | E30162611AF1BBA100730D27 /* APDynamicHeaderTableViewController */ = { 119 | isa = PBXNativeTarget; 120 | buildConfigurationList = E30162811AF1BBA200730D27 /* Build configuration list for PBXNativeTarget "APDynamicHeaderTableViewController" */; 121 | buildPhases = ( 122 | E301625E1AF1BBA100730D27 /* Sources */, 123 | E301625F1AF1BBA100730D27 /* Frameworks */, 124 | E30162601AF1BBA100730D27 /* Resources */, 125 | ); 126 | buildRules = ( 127 | ); 128 | dependencies = ( 129 | ); 130 | name = APDynamicHeaderTableViewController; 131 | productName = APDynamicHeaderTableViewController; 132 | productReference = E30162621AF1BBA100730D27 /* APDynamicHeaderTableViewController.app */; 133 | productType = "com.apple.product-type.application"; 134 | }; 135 | E30162761AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests */ = { 136 | isa = PBXNativeTarget; 137 | buildConfigurationList = E30162841AF1BBA200730D27 /* Build configuration list for PBXNativeTarget "APDynamicHeaderTableViewControllerTests" */; 138 | buildPhases = ( 139 | E30162731AF1BBA200730D27 /* Sources */, 140 | E30162741AF1BBA200730D27 /* Frameworks */, 141 | E30162751AF1BBA200730D27 /* Resources */, 142 | ); 143 | buildRules = ( 144 | ); 145 | dependencies = ( 146 | E30162791AF1BBA200730D27 /* PBXTargetDependency */, 147 | ); 148 | name = APDynamicHeaderTableViewControllerTests; 149 | productName = APDynamicHeaderTableViewControllerTests; 150 | productReference = E30162771AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests.xctest */; 151 | productType = "com.apple.product-type.bundle.unit-test"; 152 | }; 153 | /* End PBXNativeTarget section */ 154 | 155 | /* Begin PBXProject section */ 156 | E301625A1AF1BBA100730D27 /* Project object */ = { 157 | isa = PBXProject; 158 | attributes = { 159 | LastUpgradeCheck = 0630; 160 | ORGANIZATIONNAME = "Aaron Pang"; 161 | TargetAttributes = { 162 | E30162611AF1BBA100730D27 = { 163 | CreatedOnToolsVersion = 6.3; 164 | }; 165 | E30162761AF1BBA200730D27 = { 166 | CreatedOnToolsVersion = 6.3; 167 | TestTargetID = E30162611AF1BBA100730D27; 168 | }; 169 | }; 170 | }; 171 | buildConfigurationList = E301625D1AF1BBA100730D27 /* Build configuration list for PBXProject "APDynamicHeaderTableViewController" */; 172 | compatibilityVersion = "Xcode 3.2"; 173 | developmentRegion = English; 174 | hasScannedForEncodings = 0; 175 | knownRegions = ( 176 | en, 177 | Base, 178 | ); 179 | mainGroup = E30162591AF1BBA100730D27; 180 | productRefGroup = E30162631AF1BBA100730D27 /* Products */; 181 | projectDirPath = ""; 182 | projectRoot = ""; 183 | targets = ( 184 | E30162611AF1BBA100730D27 /* APDynamicHeaderTableViewController */, 185 | E30162761AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests */, 186 | ); 187 | }; 188 | /* End PBXProject section */ 189 | 190 | /* Begin PBXResourcesBuildPhase section */ 191 | E30162601AF1BBA100730D27 /* Resources */ = { 192 | isa = PBXResourcesBuildPhase; 193 | buildActionMask = 2147483647; 194 | files = ( 195 | E301626F1AF1BBA100730D27 /* Images.xcassets in Resources */, 196 | ); 197 | runOnlyForDeploymentPostprocessing = 0; 198 | }; 199 | E30162751AF1BBA200730D27 /* Resources */ = { 200 | isa = PBXResourcesBuildPhase; 201 | buildActionMask = 2147483647; 202 | files = ( 203 | ); 204 | runOnlyForDeploymentPostprocessing = 0; 205 | }; 206 | /* End PBXResourcesBuildPhase section */ 207 | 208 | /* Begin PBXSourcesBuildPhase section */ 209 | E301625E1AF1BBA100730D27 /* Sources */ = { 210 | isa = PBXSourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | E301628C1AF1BBB700730D27 /* SampleViewController.swift in Sources */, 214 | E30162891AF1BBB000730D27 /* APDynamicHeaderView.swift in Sources */, 215 | E30162681AF1BBA100730D27 /* AppDelegate.swift in Sources */, 216 | E301628A1AF1BBB000730D27 /* APDynamicHeaderTableViewController.swift in Sources */, 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | }; 220 | E30162731AF1BBA200730D27 /* Sources */ = { 221 | isa = PBXSourcesBuildPhase; 222 | buildActionMask = 2147483647; 223 | files = ( 224 | E301627E1AF1BBA200730D27 /* APDynamicHeaderTableViewControllerTests.swift in Sources */, 225 | ); 226 | runOnlyForDeploymentPostprocessing = 0; 227 | }; 228 | /* End PBXSourcesBuildPhase section */ 229 | 230 | /* Begin PBXTargetDependency section */ 231 | E30162791AF1BBA200730D27 /* PBXTargetDependency */ = { 232 | isa = PBXTargetDependency; 233 | target = E30162611AF1BBA100730D27 /* APDynamicHeaderTableViewController */; 234 | targetProxy = E30162781AF1BBA200730D27 /* PBXContainerItemProxy */; 235 | }; 236 | /* End PBXTargetDependency section */ 237 | 238 | /* Begin XCBuildConfiguration section */ 239 | E301627F1AF1BBA200730D27 /* Debug */ = { 240 | isa = XCBuildConfiguration; 241 | buildSettings = { 242 | ALWAYS_SEARCH_USER_PATHS = NO; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_WARN_BOOL_CONVERSION = YES; 248 | CLANG_WARN_CONSTANT_CONVERSION = YES; 249 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 250 | CLANG_WARN_EMPTY_BODY = YES; 251 | CLANG_WARN_ENUM_CONVERSION = YES; 252 | CLANG_WARN_INT_CONVERSION = YES; 253 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 257 | COPY_PHASE_STRIP = NO; 258 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 259 | ENABLE_STRICT_OBJC_MSGSEND = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_DYNAMIC_NO_PIC = NO; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_OPTIMIZATION_LEVEL = 0; 264 | GCC_PREPROCESSOR_DEFINITIONS = ( 265 | "DEBUG=1", 266 | "$(inherited)", 267 | ); 268 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 269 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 270 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 271 | GCC_WARN_UNDECLARED_SELECTOR = YES; 272 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 273 | GCC_WARN_UNUSED_FUNCTION = YES; 274 | GCC_WARN_UNUSED_VARIABLE = YES; 275 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 276 | MTL_ENABLE_DEBUG_INFO = YES; 277 | ONLY_ACTIVE_ARCH = YES; 278 | SDKROOT = iphoneos; 279 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 280 | TARGETED_DEVICE_FAMILY = "1,2"; 281 | }; 282 | name = Debug; 283 | }; 284 | E30162801AF1BBA200730D27 /* Release */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ALWAYS_SEARCH_USER_PATHS = NO; 288 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 289 | CLANG_CXX_LIBRARY = "libc++"; 290 | CLANG_ENABLE_MODULES = YES; 291 | CLANG_ENABLE_OBJC_ARC = YES; 292 | CLANG_WARN_BOOL_CONVERSION = YES; 293 | CLANG_WARN_CONSTANT_CONVERSION = YES; 294 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 295 | CLANG_WARN_EMPTY_BODY = YES; 296 | CLANG_WARN_ENUM_CONVERSION = YES; 297 | CLANG_WARN_INT_CONVERSION = YES; 298 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 299 | CLANG_WARN_UNREACHABLE_CODE = YES; 300 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 301 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 302 | COPY_PHASE_STRIP = NO; 303 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 304 | ENABLE_NS_ASSERTIONS = NO; 305 | ENABLE_STRICT_OBJC_MSGSEND = YES; 306 | GCC_C_LANGUAGE_STANDARD = gnu99; 307 | GCC_NO_COMMON_BLOCKS = YES; 308 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 309 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 310 | GCC_WARN_UNDECLARED_SELECTOR = YES; 311 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 312 | GCC_WARN_UNUSED_FUNCTION = YES; 313 | GCC_WARN_UNUSED_VARIABLE = YES; 314 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 315 | MTL_ENABLE_DEBUG_INFO = NO; 316 | SDKROOT = iphoneos; 317 | TARGETED_DEVICE_FAMILY = "1,2"; 318 | VALIDATE_PRODUCT = YES; 319 | }; 320 | name = Release; 321 | }; 322 | E30162821AF1BBA200730D27 /* Debug */ = { 323 | isa = XCBuildConfiguration; 324 | buildSettings = { 325 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 326 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 327 | INFOPLIST_FILE = APDynamicHeaderTableViewController/Info.plist; 328 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 329 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 330 | PRODUCT_NAME = "$(TARGET_NAME)"; 331 | }; 332 | name = Debug; 333 | }; 334 | E30162831AF1BBA200730D27 /* Release */ = { 335 | isa = XCBuildConfiguration; 336 | buildSettings = { 337 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 338 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 339 | INFOPLIST_FILE = APDynamicHeaderTableViewController/Info.plist; 340 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 341 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 342 | PRODUCT_NAME = "$(TARGET_NAME)"; 343 | }; 344 | name = Release; 345 | }; 346 | E30162851AF1BBA200730D27 /* Debug */ = { 347 | isa = XCBuildConfiguration; 348 | buildSettings = { 349 | BUNDLE_LOADER = "$(TEST_HOST)"; 350 | FRAMEWORK_SEARCH_PATHS = ( 351 | "$(SDKROOT)/Developer/Library/Frameworks", 352 | "$(inherited)", 353 | ); 354 | GCC_PREPROCESSOR_DEFINITIONS = ( 355 | "DEBUG=1", 356 | "$(inherited)", 357 | ); 358 | INFOPLIST_FILE = APDynamicHeaderTableViewControllerTests/Info.plist; 359 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 360 | PRODUCT_NAME = "$(TARGET_NAME)"; 361 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/APDynamicHeaderTableViewController.app/APDynamicHeaderTableViewController"; 362 | }; 363 | name = Debug; 364 | }; 365 | E30162861AF1BBA200730D27 /* Release */ = { 366 | isa = XCBuildConfiguration; 367 | buildSettings = { 368 | BUNDLE_LOADER = "$(TEST_HOST)"; 369 | FRAMEWORK_SEARCH_PATHS = ( 370 | "$(SDKROOT)/Developer/Library/Frameworks", 371 | "$(inherited)", 372 | ); 373 | INFOPLIST_FILE = APDynamicHeaderTableViewControllerTests/Info.plist; 374 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 375 | PRODUCT_NAME = "$(TARGET_NAME)"; 376 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/APDynamicHeaderTableViewController.app/APDynamicHeaderTableViewController"; 377 | }; 378 | name = Release; 379 | }; 380 | /* End XCBuildConfiguration section */ 381 | 382 | /* Begin XCConfigurationList section */ 383 | E301625D1AF1BBA100730D27 /* Build configuration list for PBXProject "APDynamicHeaderTableViewController" */ = { 384 | isa = XCConfigurationList; 385 | buildConfigurations = ( 386 | E301627F1AF1BBA200730D27 /* Debug */, 387 | E30162801AF1BBA200730D27 /* Release */, 388 | ); 389 | defaultConfigurationIsVisible = 0; 390 | defaultConfigurationName = Release; 391 | }; 392 | E30162811AF1BBA200730D27 /* Build configuration list for PBXNativeTarget "APDynamicHeaderTableViewController" */ = { 393 | isa = XCConfigurationList; 394 | buildConfigurations = ( 395 | E30162821AF1BBA200730D27 /* Debug */, 396 | E30162831AF1BBA200730D27 /* Release */, 397 | ); 398 | defaultConfigurationIsVisible = 0; 399 | defaultConfigurationName = Release; 400 | }; 401 | E30162841AF1BBA200730D27 /* Build configuration list for PBXNativeTarget "APDynamicHeaderTableViewControllerTests" */ = { 402 | isa = XCConfigurationList; 403 | buildConfigurations = ( 404 | E30162851AF1BBA200730D27 /* Debug */, 405 | E30162861AF1BBA200730D27 /* Release */, 406 | ); 407 | defaultConfigurationIsVisible = 0; 408 | defaultConfigurationName = Release; 409 | }; 410 | /* End XCConfigurationList section */ 411 | }; 412 | rootObject = E301625A1AF1BBA100730D27 /* Project object */; 413 | } 414 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController.xcodeproj/xcuserdata/aaronpang.xcuserdatad/xcschemes/APDynamicHeaderTableViewController.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController.xcodeproj/xcuserdata/aaronpang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | APDynamicHeaderTableViewController.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E30162611AF1BBA100730D27 16 | 17 | primary 18 | 19 | 20 | E30162761AF1BBA200730D27 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController/APDynamicHeaderTableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APDynamicHeaderTableViewController.swift 3 | // 4 | // Created by Aaron Pang on 2015-04-27. 5 | // Copyright (c) 2015 Aaron Pang. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | class APDynamicHeaderTableViewController : UIViewController { 12 | let headerView = APDynamicHeaderView () 13 | let tableView = UITableView (frame: CGRectZero, style: .Plain) 14 | 15 | private var headerViewHeightConstraint = NSLayoutConstraint() 16 | private var headerBeganCollapsed = false 17 | private var collapsedHeaderViewHeight : CGFloat = UIApplication.sharedApplication().statusBarFrame.height 18 | private var expandedHeaderViewHeight : CGFloat = 75 19 | private var headerExpandDelay : CGFloat = 100 20 | private var tableViewScrollOffsetBeginDraggingY : CGFloat = 0.0 21 | 22 | /** 23 | Designated Initializer. Initializes table view controller and header view. 24 | 25 | :param: collapsedHeaderViewHeight Height of header view when collapsed. 26 | :param: expandedHeaderViewHeight Height of header view when expanded. 27 | :param: headerExpandDelay Delay for header view to begin expanding when user is scrolling up. 28 | 29 | */ 30 | init(collapsedHeaderViewHeight : CGFloat, expandedHeaderViewHeight : CGFloat, headerExpandDelay :CGFloat) { 31 | self.collapsedHeaderViewHeight = collapsedHeaderViewHeight 32 | self.expandedHeaderViewHeight = expandedHeaderViewHeight 33 | self.headerExpandDelay = headerExpandDelay 34 | super.init(nibName: nil, bundle: nil) 35 | tableView.dataSource = self 36 | tableView.delegate = self 37 | } 38 | 39 | /** 40 | Initializes table view controller and header view with default values. 41 | */ 42 | init () { 43 | super.init(nibName: nil, bundle: nil) 44 | tableView.dataSource = self 45 | tableView.delegate = self 46 | } 47 | 48 | required init(coder aDecoder: NSCoder) { 49 | fatalError("init(coder:) has not been implemented") 50 | } 51 | 52 | override func loadView() { 53 | super.loadView() 54 | 55 | headerView.setTranslatesAutoresizingMaskIntoConstraints(false) 56 | tableView.setTranslatesAutoresizingMaskIntoConstraints(false) 57 | 58 | view.addSubview(headerView) 59 | view.addSubview(tableView) 60 | tableView.backgroundColor = UIColor.whiteColor() 61 | 62 | let views = ["headerView" : headerView, "tableView" : tableView] 63 | view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[headerView]|", options: NSLayoutFormatOptions(0), metrics: nil, views: views)) 64 | view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[tableView]|", options: NSLayoutFormatOptions(0), metrics: nil, views: views)) 65 | view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[headerView][tableView]|", options: NSLayoutFormatOptions(0), metrics: nil, views: views)) 66 | 67 | headerViewHeightConstraint = NSLayoutConstraint(item: headerView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: expandedHeaderViewHeight) 68 | view.addConstraint(headerViewHeightConstraint) 69 | } 70 | 71 | func animateHeaderViewHeight () -> Void { 72 | // Animate the header view to collapsed or expanded if it is dragged only partially 73 | var headerViewHeightDestinationConstant : CGFloat = 0.0 74 | if (headerViewHeightConstraint.constant < ((expandedHeaderViewHeight - collapsedHeaderViewHeight) / 2.0 + collapsedHeaderViewHeight)) { 75 | headerViewHeightDestinationConstant = collapsedHeaderViewHeight 76 | } else { 77 | headerViewHeightDestinationConstant = expandedHeaderViewHeight 78 | } 79 | if (headerViewHeightConstraint.constant != expandedHeaderViewHeight && headerViewHeightConstraint.constant != collapsedHeaderViewHeight) { 80 | let animationDuration = 0.25 81 | UIView.animateWithDuration(animationDuration, animations: { () -> Void in 82 | self.headerViewHeightConstraint.constant = headerViewHeightDestinationConstant 83 | let progress = (self.headerViewHeightConstraint.constant - self.collapsedHeaderViewHeight) / (self.expandedHeaderViewHeight - self.collapsedHeaderViewHeight) 84 | self.headerView.expandToProgress(progress) 85 | self.view.layoutIfNeeded() 86 | }) 87 | } 88 | } 89 | } 90 | 91 | extension APDynamicHeaderTableViewController : UITableViewDelegate { 92 | 93 | } 94 | 95 | extension APDynamicHeaderTableViewController : UIScrollViewDelegate { 96 | func scrollViewWillBeginDragging(scrollView: UIScrollView) { 97 | // Clamp the beginning point to 0 and the max content offset to prevent unintentional resizing when dragging during rubber banding 98 | tableViewScrollOffsetBeginDraggingY = min(max(scrollView.contentOffset.y, 0), scrollView.contentSize.height - scrollView.frame.size.height) 99 | 100 | // Keep track of whether or not the header was collapsed to determine if we can add the delay of expansion 101 | headerBeganCollapsed = (headerViewHeightConstraint.constant == collapsedHeaderViewHeight) 102 | } 103 | 104 | func scrollViewDidScroll(scrollView: UIScrollView) { 105 | // Do nothing if the table view is not scrollable 106 | if tableView.contentSize.height < CGRectGetHeight(tableView.bounds) { 107 | return 108 | } 109 | var contentOffsetY = tableView.contentOffset.y - tableViewScrollOffsetBeginDraggingY 110 | // Add a delay to expanding the header only if the user began scrolling below the allotted amount of space to actually expand the header with no delay (e.g. If it takes 30 pixels to scroll up the scrollview to expand the header then don't add the delay of the user started scrolling at 10 pixels) 111 | 112 | if tableViewScrollOffsetBeginDraggingY > ((expandedHeaderViewHeight - collapsedHeaderViewHeight) + headerExpandDelay) && contentOffsetY < 0 && headerBeganCollapsed { 113 | contentOffsetY = contentOffsetY + headerExpandDelay 114 | } 115 | // Calculate how much the header height will change so we can readjust the table view's content offset so it doesn't scroll while we change the height of the header 116 | let changeInHeaderViewHeight = headerViewHeightConstraint.constant - min(max(headerViewHeightConstraint.constant - contentOffsetY, collapsedHeaderViewHeight), expandedHeaderViewHeight) 117 | headerViewHeightConstraint.constant = min(max(headerViewHeightConstraint.constant - contentOffsetY, collapsedHeaderViewHeight), expandedHeaderViewHeight) 118 | let progress = (headerViewHeightConstraint.constant - collapsedHeaderViewHeight) / (expandedHeaderViewHeight - collapsedHeaderViewHeight) 119 | headerView.expandToProgress(progress) 120 | 121 | // When the header view height is changing, freeze the content in the table view 122 | if headerViewHeightConstraint.constant != collapsedHeaderViewHeight && headerViewHeightConstraint.constant != expandedHeaderViewHeight { 123 | tableView.contentOffset = CGPointMake(0, tableView.contentOffset.y - changeInHeaderViewHeight) 124 | } 125 | } 126 | 127 | // Animate the header view when the user ends dragging or flicks the scroll view 128 | func scrollViewDidEndDecelerating(scrollView: UIScrollView) { 129 | animateHeaderViewHeight() 130 | } 131 | 132 | func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { 133 | animateHeaderViewHeight() 134 | } 135 | } 136 | 137 | extension APDynamicHeaderTableViewController : UITableViewDataSource { 138 | func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 139 | return 20 140 | } 141 | 142 | func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 143 | var tableViewCell : UITableViewCell 144 | if let dequeuedTableViewCell = tableView.dequeueReusableCellWithIdentifier("Identifier") as? UITableViewCell { 145 | tableViewCell = dequeuedTableViewCell 146 | } else { 147 | tableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Identifier") 148 | tableViewCell.selectionStyle = .None 149 | } 150 | tableViewCell.textLabel?.text = String(indexPath.row) 151 | return tableViewCell 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController/APDynamicHeaderView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APDynamicHeaderView.swift 3 | // 4 | // Created by Aaron Pang on 2015-04-26. 5 | // Copyright (c) 2015 Aaron Pang. All rights reserved. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | class APDynamicHeaderView : UIView { 12 | 13 | var contentView = UIView() 14 | private let textLabel = UILabel() 15 | 16 | // MARK: Lifecycle 17 | 18 | /** 19 | Designated Initializer. Defaults the size of the header view to the expanded size. 20 | */ 21 | init() { 22 | super.init(frame: CGRectZero) 23 | self.backgroundColor = UIColor(red: 0.2, green: 0.5, blue: 0.9, alpha: 1) 24 | 25 | addSubview(contentView) 26 | 27 | contentView.backgroundColor = .clearColor() 28 | contentView.setTranslatesAutoresizingMaskIntoConstraints(false) 29 | 30 | textLabel.setTranslatesAutoresizingMaskIntoConstraints(false) 31 | textLabel.text = "Title" 32 | textLabel.textAlignment = .Center 33 | textLabel.font = UIFont(name: "Helvetica Neue", size: 25) 34 | contentView.addSubview(textLabel) 35 | 36 | let views = ["contentView" : contentView, "textLabel" : textLabel] 37 | let metrics = ["statusBarHeight" : UIApplication.sharedApplication().statusBarFrame.height] 38 | addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[contentView]|", options: NSLayoutFormatOptions(0), metrics: nil, views: views)) 39 | addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[contentView]|", options: NSLayoutFormatOptions(0), metrics: nil, views: views)) 40 | 41 | contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[textLabel]|", options: NSLayoutFormatOptions(0), metrics: metrics, views: views)) 42 | contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(statusBarHeight)-[textLabel]|", options: NSLayoutFormatOptions(0), metrics: metrics, views: views)) 43 | } 44 | 45 | required init(coder aDecoder: NSCoder) { 46 | super.init(coder: aDecoder) 47 | } 48 | 49 | func expandToProgress(progress : CGFloat) { 50 | contentView.alpha = progress 51 | contentView.transform = CGAffineTransformMakeScale(progress, progress) 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // APDynamicHeaderTableViewController 4 | // 5 | // Created by Aaron Pang on 2015-04-29. 6 | // Copyright (c) 2015 Aaron Pang. 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: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | let sampleViewController = SampleViewController() 20 | 21 | window = UIWindow(frame: UIScreen.mainScreen().bounds) 22 | if let window = window { 23 | window.backgroundColor = UIColor.whiteColor() 24 | window.makeKeyAndVisible() 25 | window.rootViewController = sampleViewController 26 | } 27 | return true 28 | } 29 | 30 | func applicationWillResignActive(application: UIApplication) { 31 | // 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. 32 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 33 | } 34 | 35 | func applicationDidEnterBackground(application: UIApplication) { 36 | // 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. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | func applicationWillEnterForeground(application: UIApplication) { 41 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 42 | } 43 | 44 | func applicationDidBecomeActive(application: UIApplication) { 45 | // 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. 46 | } 47 | 48 | func applicationWillTerminate(application: UIApplication) { 49 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 50 | } 51 | 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "ipad", 6 | "minimum-system-version" : "7.0", 7 | "extent" : "full-screen", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "landscape", 12 | "idiom" : "ipad", 13 | "minimum-system-version" : "7.0", 14 | "extent" : "full-screen", 15 | "scale" : "1x" 16 | }, 17 | { 18 | "orientation" : "landscape", 19 | "idiom" : "ipad", 20 | "minimum-system-version" : "7.0", 21 | "extent" : "full-screen", 22 | "scale" : "2x" 23 | }, 24 | { 25 | "orientation" : "portrait", 26 | "idiom" : "iphone", 27 | "minimum-system-version" : "7.0", 28 | "scale" : "2x" 29 | }, 30 | { 31 | "orientation" : "portrait", 32 | "idiom" : "iphone", 33 | "minimum-system-version" : "7.0", 34 | "subtype" : "retina4", 35 | "scale" : "2x" 36 | }, 37 | { 38 | "orientation" : "portrait", 39 | "idiom" : "ipad", 40 | "minimum-system-version" : "7.0", 41 | "extent" : "full-screen", 42 | "scale" : "1x" 43 | } 44 | ], 45 | "info" : { 46 | "version" : 1, 47 | "author" : "xcode" 48 | } 49 | } -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | aaronpang.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewController/SampleViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SampleViewController.swift 3 | // Eurotrip 4 | // 5 | // Created by Aaron Pang on 2015-04-27. 6 | // Copyright (c) 2015 Aaron Pang. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | class SampleViewController : APDynamicHeaderTableViewController { 13 | override init() { 14 | super.init( 15 | collapsedHeaderViewHeight: UIApplication.sharedApplication().statusBarFrame.height, 16 | expandedHeaderViewHeight: 75, 17 | headerExpandDelay: 100) 18 | 19 | tableView.dataSource = self 20 | } 21 | 22 | required init(coder aDecoder: NSCoder) { 23 | fatalError("init(coder:) has not been implemented") 24 | } 25 | } 26 | 27 | extension SampleViewController : UITableViewDataSource { 28 | override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 29 | return 20 30 | } 31 | } -------------------------------------------------------------------------------- /APDynamicHeaderTableViewControllerTests/APDynamicHeaderTableViewControllerTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APDynamicHeaderTableViewControllerTests.swift 3 | // APDynamicHeaderTableViewControllerTests 4 | // 5 | // Created by Aaron Pang on 2015-04-29. 6 | // Copyright (c) 2015 Aaron Pang. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class APDynamicHeaderTableViewControllerTests: 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 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /APDynamicHeaderTableViewControllerTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | aaronpang.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Gifs/one.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronpang/APDynamicHeaderTableViewController/5bf282f6a31dba958474775c58cafd27d7dfb5bc/Gifs/one.gif -------------------------------------------------------------------------------- /Gifs/two.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronpang/APDynamicHeaderTableViewController/5bf282f6a31dba958474775c58cafd27d7dfb5bc/Gifs/two.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Aaron Pang 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # APDynamicHeaderTableViewController 2 | 3 | A simple table view controller with a header view made as a recreation of the Instagram header written in Swift. It's a very simple control that I whipped up in a few days and the header is simply a UIView so you can tweak it, add images, or even make it a tableview. I loved the way the Instagram header was so simple and how it collapsed and expanded when you scrolled so I made a simple clone of it. 4 | 5 |

6 | 7 | 8 |

9 | 10 | ## How to Install ## 11 | 12 | Support for Cocoapods! Simply add the following to your Podfile: 13 | 14 | pod 'APDynamicHeaderTableViewController', '~>0.1.1' 15 | 16 | Drag and drop the APDynamicHeaderTableViewController.swift and APDynamicHeaderView.swift into your project. Subclass the APDynamicHeaderTableViewController class and set the tableview's data source and delegate to the new subclass. 17 | 18 | ## Usage ## 19 | 20 | To use the APDynamicHeaderTableViewController simply subclass it and call one of the two initializers. Then, override the tableview's data source to input your own data and cells. 21 | 22 | ```swift 23 | override init() { 24 | super.init( 25 | collapsedHeaderViewHeight: UIApplication.sharedApplication().statusBarFrame.height, 26 | expandedHeaderViewHeight: 75, 27 | headerExpandDelay: 100) 28 | 29 | tableView.dataSource = self 30 | } 31 | 32 | override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 33 | return 20 34 | } 35 | ``` 36 | 37 | There are 2 initializers. The first one is the default init() function that sets all the default values. The second one lets you pass in 3 parameters, the collapsed header height, the expanded header height, and the delay for the header to be expanded when the user is scrolling up. 38 | 39 | ```swift 40 | init () 41 | 42 | init(collapsedHeaderViewHeight : CGFloat, expandedHeaderViewHeight : CGFloat, headerExpandDelay :CGFloat) 43 | ``` 44 | 45 | ## Properties 46 | 47 | ***APDynamicTableViewController*** 48 | 49 | ```swift 50 | let headerView 51 | ``` 52 | 53 | The header view at the top of the table view. Set the content view of this header view to be anything you like. The default is simply a text label in the middle. 54 | 55 | ```swift 56 | let tableView 57 | ``` 58 | 59 | The table view. Simply set the data source and delegate for the table view and adjust the info in the table view when need be. 60 | 61 | ***APDynamicHeaderView*** 62 | 63 | ```swift 64 | var contentView 65 | ``` 66 | 67 | The content of the header view. Set this content view to be any UIView you like. Default is a text label in the middle. 68 | 69 | ## Contact 70 | 71 | * [@aaronpango](https://twitter.com/AaronPango) on Twitter 72 | * pang.aaron56 [at] gmail [dot] com 73 | 74 | ## License 75 | 76 | MIT License 77 | --------------------------------------------------------------------------------