├── .gitignore ├── .swift-version ├── .swiftlint.yml ├── LICENSE ├── README.md ├── StickyHeader.podspec ├── StickyHeader.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata ├── xcshareddata │ └── xcschemes │ │ └── StickyHeader.xcscheme └── xcuserdata │ └── yheinrich.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── StickyHeader ├── Info.plist ├── StickyHeader.h ├── StickyHeader.swift ├── StickyHeaderView.swift └── UIScrollViewExtension.swift └── TestApp ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── ViewController.swift ├── ViewControllerTwo.swift └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | ### Xcode ### 2 | .build/ 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 | *.xcuserstate 17 | timeline.xctimeline 18 | 19 | /Framework 20 | Carthage/ 21 | screenshots/ 22 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 3.0.1 2 | -------------------------------------------------------------------------------- /.swiftlint.yml: -------------------------------------------------------------------------------- 1 | included: 2 | - StickyHeader 3 | disabled_rules: 4 | - line_length 5 | - variable_name 6 | opt_in_rules: 7 | - empty_count -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Yannick Heinrich 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) 3 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 4 | [![CocoaPods Compatible](https://img.shields.io/cocoapods/v/StickyHeader.svg)](https://img.shields.io/cocoapods/v/StickyHeader.svg) 5 | [![Platform](https://img.shields.io/cocoapods/p/StickyHeader.svg?style=flat)](http://cocoadocs.org/docsets/StickyHeader) 6 | 7 | # StickyHeader 8 | 9 | Simple library based on work done on [MXParallaxHeader](https://github.com/maxep/MXParallaxHeader) helping to 10 | create a sticky header for an UIScrollView. 11 | 12 | ![Demo](TestApp/demo.gif) 13 | 14 | ## Installation 15 | 16 | ### CocoaPods 17 | 18 | ``` 19 | pod "StickyHeader" 20 | ``` 21 | 22 | ### Carthage 23 | ``` 24 | github "yageek/StickyHeader" 25 | ``` 26 | 27 | ## Usage 28 | 29 | To add a sticky header: 30 | 31 | ```swift 32 | 33 | // Create the header 34 | let view = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 100)) 35 | view.backgroundColor = UIColor.blueColor() 36 | view.translatesAutoresizingMaskIntoConstraints = false 37 | 38 | // Add the header to the table view 39 | self.tableView.stickyHeader.view = self.headerView 40 | self.tableView.stickyHeader.height = 200 41 | self.tableView.stickyHeader.minimumHeight = 100 42 | ``` 43 | 44 | ## Changelog 45 | - 2.0.0: Swift 3. compatible. 46 | - 1.0.1: Swift 2.3 compatible. 47 | - 1.0.0: First release. 48 | 49 | ## License 50 | 51 | StickyHeader is released under the MIT license. See LICENSE for details. 52 | -------------------------------------------------------------------------------- /StickyHeader.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "StickyHeader" 4 | s.version = "2.0.0" 5 | s.summary = "Library helping to add a sticky header to an UIScrollView." 6 | s.description = <<-DESC 7 | Library helping to add a sticky header to an UIScrollView. 8 | The code is based on https://github.com/maxep/MXParallaxHeader. 9 | DESC 10 | s.homepage = "https://github.com/yageek/StickyHeader" 11 | s.license = "MIT" 12 | s.author = { "Yannick Heinrich" => "yannick.heinrich@gmail.com" } 13 | s.source = { :git => "https://github.com/yageek/StickyHeader.git", :tag => "#{s.version}" } 14 | s.source_files = "StickyHeader" 15 | s.platform = :ios 16 | s.ios.deployment_target = '8.0' 17 | end 18 | 19 | -------------------------------------------------------------------------------- /StickyHeader.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0B3ABB181D6DF12400479F1D /* StickyHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 0B3ABB171D6DF12400479F1D /* StickyHeader.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | 0B3ABB201D6DF14D00479F1D /* StickyHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3ABB1F1D6DF14D00479F1D /* StickyHeader.swift */; }; 12 | 0B3ABB251D6DF5F700479F1D /* StickyHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3ABB241D6DF5F700479F1D /* StickyHeaderView.swift */; }; 13 | 0BA68E491DF043F100B9EBB8 /* StickyHeader.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3ABB141D6DF12400479F1D /* StickyHeader.framework */; }; 14 | 0BA68E4A1DF043F100B9EBB8 /* StickyHeader.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3ABB141D6DF12400479F1D /* StickyHeader.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 15 | 0BBC459E1D703CE300D536AE /* ViewControllerTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BBC459D1D703CE300D536AE /* ViewControllerTwo.swift */; }; 16 | 0BD75F541D6F32C300A2E6CD /* UIScrollViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD75F531D6F32C300A2E6CD /* UIScrollViewExtension.swift */; }; 17 | 0BD75F721D6F348200A2E6CD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD75F711D6F348200A2E6CD /* AppDelegate.swift */; }; 18 | 0BD75F771D6F348200A2E6CD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0BD75F751D6F348200A2E6CD /* Main.storyboard */; }; 19 | 0BD75F791D6F348200A2E6CD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0BD75F781D6F348200A2E6CD /* Assets.xcassets */; }; 20 | 0BD75F7C1D6F348200A2E6CD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0BD75F7A1D6F348200A2E6CD /* LaunchScreen.storyboard */; }; 21 | 0BD75F821D6F34CB00A2E6CD /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD75F811D6F34CB00A2E6CD /* ViewController.swift */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXContainerItemProxy section */ 25 | 0BA68E4B1DF043F100B9EBB8 /* PBXContainerItemProxy */ = { 26 | isa = PBXContainerItemProxy; 27 | containerPortal = 0B3ABB0B1D6DF12400479F1D /* Project object */; 28 | proxyType = 1; 29 | remoteGlobalIDString = 0B3ABB131D6DF12400479F1D; 30 | remoteInfo = StickyHeader; 31 | }; 32 | /* End PBXContainerItemProxy section */ 33 | 34 | /* Begin PBXCopyFilesBuildPhase section */ 35 | 0BA68E4D1DF043F100B9EBB8 /* Embed Frameworks */ = { 36 | isa = PBXCopyFilesBuildPhase; 37 | buildActionMask = 2147483647; 38 | dstPath = ""; 39 | dstSubfolderSpec = 10; 40 | files = ( 41 | 0BA68E4A1DF043F100B9EBB8 /* StickyHeader.framework in Embed Frameworks */, 42 | ); 43 | name = "Embed Frameworks"; 44 | runOnlyForDeploymentPostprocessing = 0; 45 | }; 46 | /* End PBXCopyFilesBuildPhase section */ 47 | 48 | /* Begin PBXFileReference section */ 49 | 0B3ABB141D6DF12400479F1D /* StickyHeader.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = StickyHeader.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 0B3ABB171D6DF12400479F1D /* StickyHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StickyHeader.h; sourceTree = ""; }; 51 | 0B3ABB191D6DF12400479F1D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | 0B3ABB1F1D6DF14D00479F1D /* StickyHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickyHeader.swift; sourceTree = ""; }; 53 | 0B3ABB211D6DF22E00479F1D /* .swiftlint.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 54 | 0B3ABB241D6DF5F700479F1D /* StickyHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickyHeaderView.swift; sourceTree = ""; }; 55 | 0BA68E451DF03F5B00B9EBB8 /* .swift-version */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".swift-version"; sourceTree = ""; }; 56 | 0BBC459D1D703CE300D536AE /* ViewControllerTwo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerTwo.swift; sourceTree = ""; }; 57 | 0BD75F531D6F32C300A2E6CD /* UIScrollViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIScrollViewExtension.swift; sourceTree = ""; }; 58 | 0BD75F6F1D6F348200A2E6CD /* TestApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 59 | 0BD75F711D6F348200A2E6CD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 60 | 0BD75F761D6F348200A2E6CD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 61 | 0BD75F781D6F348200A2E6CD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 62 | 0BD75F7B1D6F348200A2E6CD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 63 | 0BD75F7D1D6F348200A2E6CD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 64 | 0BD75F811D6F34CB00A2E6CD /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 65 | /* End PBXFileReference section */ 66 | 67 | /* Begin PBXFrameworksBuildPhase section */ 68 | 0B3ABB101D6DF12400479F1D /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | 0BD75F6C1D6F348200A2E6CD /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | 0BA68E491DF043F100B9EBB8 /* StickyHeader.framework in Frameworks */, 80 | ); 81 | runOnlyForDeploymentPostprocessing = 0; 82 | }; 83 | /* End PBXFrameworksBuildPhase section */ 84 | 85 | /* Begin PBXGroup section */ 86 | 0B3ABB0A1D6DF12400479F1D = { 87 | isa = PBXGroup; 88 | children = ( 89 | 0BA68E451DF03F5B00B9EBB8 /* .swift-version */, 90 | 0B3ABB211D6DF22E00479F1D /* .swiftlint.yml */, 91 | 0B3ABB161D6DF12400479F1D /* StickyHeader */, 92 | 0BD75F701D6F348200A2E6CD /* TestApp */, 93 | 0B3ABB151D6DF12400479F1D /* Products */, 94 | ); 95 | sourceTree = ""; 96 | }; 97 | 0B3ABB151D6DF12400479F1D /* Products */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 0B3ABB141D6DF12400479F1D /* StickyHeader.framework */, 101 | 0BD75F6F1D6F348200A2E6CD /* TestApp.app */, 102 | ); 103 | name = Products; 104 | sourceTree = ""; 105 | }; 106 | 0B3ABB161D6DF12400479F1D /* StickyHeader */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 0B3ABB171D6DF12400479F1D /* StickyHeader.h */, 110 | 0B3ABB191D6DF12400479F1D /* Info.plist */, 111 | 0B3ABB1F1D6DF14D00479F1D /* StickyHeader.swift */, 112 | 0B3ABB241D6DF5F700479F1D /* StickyHeaderView.swift */, 113 | 0BD75F531D6F32C300A2E6CD /* UIScrollViewExtension.swift */, 114 | ); 115 | path = StickyHeader; 116 | sourceTree = ""; 117 | }; 118 | 0BD75F701D6F348200A2E6CD /* TestApp */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 0BD75F711D6F348200A2E6CD /* AppDelegate.swift */, 122 | 0BD75F751D6F348200A2E6CD /* Main.storyboard */, 123 | 0BD75F781D6F348200A2E6CD /* Assets.xcassets */, 124 | 0BD75F7A1D6F348200A2E6CD /* LaunchScreen.storyboard */, 125 | 0BD75F7D1D6F348200A2E6CD /* Info.plist */, 126 | 0BD75F811D6F34CB00A2E6CD /* ViewController.swift */, 127 | 0BBC459D1D703CE300D536AE /* ViewControllerTwo.swift */, 128 | ); 129 | path = TestApp; 130 | sourceTree = ""; 131 | }; 132 | /* End PBXGroup section */ 133 | 134 | /* Begin PBXHeadersBuildPhase section */ 135 | 0B3ABB111D6DF12400479F1D /* Headers */ = { 136 | isa = PBXHeadersBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 0B3ABB181D6DF12400479F1D /* StickyHeader.h in Headers */, 140 | ); 141 | runOnlyForDeploymentPostprocessing = 0; 142 | }; 143 | /* End PBXHeadersBuildPhase section */ 144 | 145 | /* Begin PBXNativeTarget section */ 146 | 0B3ABB131D6DF12400479F1D /* StickyHeader */ = { 147 | isa = PBXNativeTarget; 148 | buildConfigurationList = 0B3ABB1C1D6DF12400479F1D /* Build configuration list for PBXNativeTarget "StickyHeader" */; 149 | buildPhases = ( 150 | 0B3ABB0F1D6DF12400479F1D /* Sources */, 151 | 0B3ABB101D6DF12400479F1D /* Frameworks */, 152 | 0B3ABB111D6DF12400479F1D /* Headers */, 153 | 0B3ABB121D6DF12400479F1D /* Resources */, 154 | 0B3ABB231D6DF23D00479F1D /* Swiftlint */, 155 | ); 156 | buildRules = ( 157 | ); 158 | dependencies = ( 159 | ); 160 | name = StickyHeader; 161 | productName = StickyHeader; 162 | productReference = 0B3ABB141D6DF12400479F1D /* StickyHeader.framework */; 163 | productType = "com.apple.product-type.framework"; 164 | }; 165 | 0BD75F6E1D6F348200A2E6CD /* TestApp */ = { 166 | isa = PBXNativeTarget; 167 | buildConfigurationList = 0BD75F7E1D6F348200A2E6CD /* Build configuration list for PBXNativeTarget "TestApp" */; 168 | buildPhases = ( 169 | 0BD75F6B1D6F348200A2E6CD /* Sources */, 170 | 0BD75F6C1D6F348200A2E6CD /* Frameworks */, 171 | 0BD75F6D1D6F348200A2E6CD /* Resources */, 172 | 0BA68E4D1DF043F100B9EBB8 /* Embed Frameworks */, 173 | ); 174 | buildRules = ( 175 | ); 176 | dependencies = ( 177 | 0BA68E4C1DF043F100B9EBB8 /* PBXTargetDependency */, 178 | ); 179 | name = TestApp; 180 | productName = TestApp; 181 | productReference = 0BD75F6F1D6F348200A2E6CD /* TestApp.app */; 182 | productType = "com.apple.product-type.application"; 183 | }; 184 | /* End PBXNativeTarget section */ 185 | 186 | /* Begin PBXProject section */ 187 | 0B3ABB0B1D6DF12400479F1D /* Project object */ = { 188 | isa = PBXProject; 189 | attributes = { 190 | LastSwiftUpdateCheck = 0730; 191 | LastUpgradeCheck = 0730; 192 | ORGANIZATIONNAME = yageek; 193 | TargetAttributes = { 194 | 0B3ABB131D6DF12400479F1D = { 195 | CreatedOnToolsVersion = 7.3.1; 196 | DevelopmentTeam = 5VGYH76875; 197 | }; 198 | 0BD75F6E1D6F348200A2E6CD = { 199 | CreatedOnToolsVersion = 7.3.1; 200 | DevelopmentTeam = 5VGYH76875; 201 | }; 202 | }; 203 | }; 204 | buildConfigurationList = 0B3ABB0E1D6DF12400479F1D /* Build configuration list for PBXProject "StickyHeader" */; 205 | compatibilityVersion = "Xcode 3.2"; 206 | developmentRegion = English; 207 | hasScannedForEncodings = 0; 208 | knownRegions = ( 209 | en, 210 | Base, 211 | ); 212 | mainGroup = 0B3ABB0A1D6DF12400479F1D; 213 | productRefGroup = 0B3ABB151D6DF12400479F1D /* Products */; 214 | projectDirPath = ""; 215 | projectRoot = ""; 216 | targets = ( 217 | 0B3ABB131D6DF12400479F1D /* StickyHeader */, 218 | 0BD75F6E1D6F348200A2E6CD /* TestApp */, 219 | ); 220 | }; 221 | /* End PBXProject section */ 222 | 223 | /* Begin PBXResourcesBuildPhase section */ 224 | 0B3ABB121D6DF12400479F1D /* Resources */ = { 225 | isa = PBXResourcesBuildPhase; 226 | buildActionMask = 2147483647; 227 | files = ( 228 | ); 229 | runOnlyForDeploymentPostprocessing = 0; 230 | }; 231 | 0BD75F6D1D6F348200A2E6CD /* Resources */ = { 232 | isa = PBXResourcesBuildPhase; 233 | buildActionMask = 2147483647; 234 | files = ( 235 | 0BD75F7C1D6F348200A2E6CD /* LaunchScreen.storyboard in Resources */, 236 | 0BD75F791D6F348200A2E6CD /* Assets.xcassets in Resources */, 237 | 0BD75F771D6F348200A2E6CD /* Main.storyboard in Resources */, 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | /* End PBXResourcesBuildPhase section */ 242 | 243 | /* Begin PBXShellScriptBuildPhase section */ 244 | 0B3ABB231D6DF23D00479F1D /* Swiftlint */ = { 245 | isa = PBXShellScriptBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | ); 249 | inputPaths = ( 250 | ); 251 | name = Swiftlint; 252 | outputPaths = ( 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | shellPath = /bin/zsh; 256 | shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; 257 | }; 258 | /* End PBXShellScriptBuildPhase section */ 259 | 260 | /* Begin PBXSourcesBuildPhase section */ 261 | 0B3ABB0F1D6DF12400479F1D /* Sources */ = { 262 | isa = PBXSourcesBuildPhase; 263 | buildActionMask = 2147483647; 264 | files = ( 265 | 0B3ABB251D6DF5F700479F1D /* StickyHeaderView.swift in Sources */, 266 | 0B3ABB201D6DF14D00479F1D /* StickyHeader.swift in Sources */, 267 | 0BD75F541D6F32C300A2E6CD /* UIScrollViewExtension.swift in Sources */, 268 | ); 269 | runOnlyForDeploymentPostprocessing = 0; 270 | }; 271 | 0BD75F6B1D6F348200A2E6CD /* Sources */ = { 272 | isa = PBXSourcesBuildPhase; 273 | buildActionMask = 2147483647; 274 | files = ( 275 | 0BD75F821D6F34CB00A2E6CD /* ViewController.swift in Sources */, 276 | 0BD75F721D6F348200A2E6CD /* AppDelegate.swift in Sources */, 277 | 0BBC459E1D703CE300D536AE /* ViewControllerTwo.swift in Sources */, 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | /* End PBXSourcesBuildPhase section */ 282 | 283 | /* Begin PBXTargetDependency section */ 284 | 0BA68E4C1DF043F100B9EBB8 /* PBXTargetDependency */ = { 285 | isa = PBXTargetDependency; 286 | target = 0B3ABB131D6DF12400479F1D /* StickyHeader */; 287 | targetProxy = 0BA68E4B1DF043F100B9EBB8 /* PBXContainerItemProxy */; 288 | }; 289 | /* End PBXTargetDependency section */ 290 | 291 | /* Begin PBXVariantGroup section */ 292 | 0BD75F751D6F348200A2E6CD /* Main.storyboard */ = { 293 | isa = PBXVariantGroup; 294 | children = ( 295 | 0BD75F761D6F348200A2E6CD /* Base */, 296 | ); 297 | name = Main.storyboard; 298 | sourceTree = ""; 299 | }; 300 | 0BD75F7A1D6F348200A2E6CD /* LaunchScreen.storyboard */ = { 301 | isa = PBXVariantGroup; 302 | children = ( 303 | 0BD75F7B1D6F348200A2E6CD /* Base */, 304 | ); 305 | name = LaunchScreen.storyboard; 306 | sourceTree = ""; 307 | }; 308 | /* End PBXVariantGroup section */ 309 | 310 | /* Begin XCBuildConfiguration section */ 311 | 0B3ABB1A1D6DF12400479F1D /* Debug */ = { 312 | isa = XCBuildConfiguration; 313 | buildSettings = { 314 | ALWAYS_SEARCH_USER_PATHS = NO; 315 | CLANG_ANALYZER_NONNULL = YES; 316 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 317 | CLANG_CXX_LIBRARY = "libc++"; 318 | CLANG_ENABLE_MODULES = YES; 319 | CLANG_ENABLE_OBJC_ARC = YES; 320 | CLANG_WARN_BOOL_CONVERSION = YES; 321 | CLANG_WARN_CONSTANT_CONVERSION = YES; 322 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 323 | CLANG_WARN_EMPTY_BODY = YES; 324 | CLANG_WARN_ENUM_CONVERSION = YES; 325 | CLANG_WARN_INT_CONVERSION = YES; 326 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 327 | CLANG_WARN_UNREACHABLE_CODE = YES; 328 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 329 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 330 | COPY_PHASE_STRIP = NO; 331 | CURRENT_PROJECT_VERSION = 1; 332 | DEBUG_INFORMATION_FORMAT = dwarf; 333 | ENABLE_STRICT_OBJC_MSGSEND = YES; 334 | ENABLE_TESTABILITY = YES; 335 | GCC_C_LANGUAGE_STANDARD = gnu99; 336 | GCC_DYNAMIC_NO_PIC = NO; 337 | GCC_NO_COMMON_BLOCKS = YES; 338 | GCC_OPTIMIZATION_LEVEL = 0; 339 | GCC_PREPROCESSOR_DEFINITIONS = ( 340 | "DEBUG=1", 341 | "$(inherited)", 342 | ); 343 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 344 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 345 | GCC_WARN_UNDECLARED_SELECTOR = YES; 346 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 347 | GCC_WARN_UNUSED_FUNCTION = YES; 348 | GCC_WARN_UNUSED_VARIABLE = YES; 349 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 350 | MTL_ENABLE_DEBUG_INFO = YES; 351 | ONLY_ACTIVE_ARCH = YES; 352 | SDKROOT = iphoneos; 353 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 354 | TARGETED_DEVICE_FAMILY = "1,2"; 355 | VERSIONING_SYSTEM = "apple-generic"; 356 | VERSION_INFO_PREFIX = ""; 357 | }; 358 | name = Debug; 359 | }; 360 | 0B3ABB1B1D6DF12400479F1D /* Release */ = { 361 | isa = XCBuildConfiguration; 362 | buildSettings = { 363 | ALWAYS_SEARCH_USER_PATHS = NO; 364 | CLANG_ANALYZER_NONNULL = YES; 365 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 366 | CLANG_CXX_LIBRARY = "libc++"; 367 | CLANG_ENABLE_MODULES = YES; 368 | CLANG_ENABLE_OBJC_ARC = YES; 369 | CLANG_WARN_BOOL_CONVERSION = YES; 370 | CLANG_WARN_CONSTANT_CONVERSION = YES; 371 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 372 | CLANG_WARN_EMPTY_BODY = YES; 373 | CLANG_WARN_ENUM_CONVERSION = YES; 374 | CLANG_WARN_INT_CONVERSION = YES; 375 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 376 | CLANG_WARN_UNREACHABLE_CODE = YES; 377 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 378 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 379 | COPY_PHASE_STRIP = NO; 380 | CURRENT_PROJECT_VERSION = 1; 381 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 382 | ENABLE_NS_ASSERTIONS = NO; 383 | ENABLE_STRICT_OBJC_MSGSEND = YES; 384 | GCC_C_LANGUAGE_STANDARD = gnu99; 385 | GCC_NO_COMMON_BLOCKS = YES; 386 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 387 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 388 | GCC_WARN_UNDECLARED_SELECTOR = YES; 389 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 390 | GCC_WARN_UNUSED_FUNCTION = YES; 391 | GCC_WARN_UNUSED_VARIABLE = YES; 392 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 393 | MTL_ENABLE_DEBUG_INFO = NO; 394 | SDKROOT = iphoneos; 395 | TARGETED_DEVICE_FAMILY = "1,2"; 396 | VALIDATE_PRODUCT = YES; 397 | VERSIONING_SYSTEM = "apple-generic"; 398 | VERSION_INFO_PREFIX = ""; 399 | }; 400 | name = Release; 401 | }; 402 | 0B3ABB1D1D6DF12400479F1D /* Debug */ = { 403 | isa = XCBuildConfiguration; 404 | buildSettings = { 405 | CLANG_ENABLE_MODULES = YES; 406 | DEFINES_MODULE = YES; 407 | DEVELOPMENT_TEAM = 5VGYH76875; 408 | DYLIB_COMPATIBILITY_VERSION = 1; 409 | DYLIB_CURRENT_VERSION = 1; 410 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 411 | INFOPLIST_FILE = StickyHeader/Info.plist; 412 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 413 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 414 | PRODUCT_BUNDLE_IDENTIFIER = net.yageek.StickyHeader; 415 | PRODUCT_NAME = "$(TARGET_NAME)"; 416 | SKIP_INSTALL = YES; 417 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 418 | SWIFT_VERSION = 3.0.1; 419 | }; 420 | name = Debug; 421 | }; 422 | 0B3ABB1E1D6DF12400479F1D /* Release */ = { 423 | isa = XCBuildConfiguration; 424 | buildSettings = { 425 | CLANG_ENABLE_MODULES = YES; 426 | DEFINES_MODULE = YES; 427 | DEVELOPMENT_TEAM = 5VGYH76875; 428 | DYLIB_COMPATIBILITY_VERSION = 1; 429 | DYLIB_CURRENT_VERSION = 1; 430 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 431 | INFOPLIST_FILE = StickyHeader/Info.plist; 432 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 433 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 434 | PRODUCT_BUNDLE_IDENTIFIER = net.yageek.StickyHeader; 435 | PRODUCT_NAME = "$(TARGET_NAME)"; 436 | SKIP_INSTALL = YES; 437 | SWIFT_VERSION = 3.0.1; 438 | }; 439 | name = Release; 440 | }; 441 | 0BD75F7F1D6F348200A2E6CD /* Debug */ = { 442 | isa = XCBuildConfiguration; 443 | buildSettings = { 444 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 445 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 446 | DEVELOPMENT_TEAM = 5VGYH76875; 447 | INFOPLIST_FILE = TestApp/Info.plist; 448 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 449 | PRODUCT_BUNDLE_IDENTIFIER = net.yageek.TestApp; 450 | PRODUCT_NAME = "$(TARGET_NAME)"; 451 | SWIFT_VERSION = 3.0.1; 452 | }; 453 | name = Debug; 454 | }; 455 | 0BD75F801D6F348200A2E6CD /* Release */ = { 456 | isa = XCBuildConfiguration; 457 | buildSettings = { 458 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 459 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 460 | DEVELOPMENT_TEAM = 5VGYH76875; 461 | INFOPLIST_FILE = TestApp/Info.plist; 462 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 463 | PRODUCT_BUNDLE_IDENTIFIER = net.yageek.TestApp; 464 | PRODUCT_NAME = "$(TARGET_NAME)"; 465 | SWIFT_VERSION = 3.0.1; 466 | }; 467 | name = Release; 468 | }; 469 | /* End XCBuildConfiguration section */ 470 | 471 | /* Begin XCConfigurationList section */ 472 | 0B3ABB0E1D6DF12400479F1D /* Build configuration list for PBXProject "StickyHeader" */ = { 473 | isa = XCConfigurationList; 474 | buildConfigurations = ( 475 | 0B3ABB1A1D6DF12400479F1D /* Debug */, 476 | 0B3ABB1B1D6DF12400479F1D /* Release */, 477 | ); 478 | defaultConfigurationIsVisible = 0; 479 | defaultConfigurationName = Release; 480 | }; 481 | 0B3ABB1C1D6DF12400479F1D /* Build configuration list for PBXNativeTarget "StickyHeader" */ = { 482 | isa = XCConfigurationList; 483 | buildConfigurations = ( 484 | 0B3ABB1D1D6DF12400479F1D /* Debug */, 485 | 0B3ABB1E1D6DF12400479F1D /* Release */, 486 | ); 487 | defaultConfigurationIsVisible = 0; 488 | defaultConfigurationName = Release; 489 | }; 490 | 0BD75F7E1D6F348200A2E6CD /* Build configuration list for PBXNativeTarget "TestApp" */ = { 491 | isa = XCConfigurationList; 492 | buildConfigurations = ( 493 | 0BD75F7F1D6F348200A2E6CD /* Debug */, 494 | 0BD75F801D6F348200A2E6CD /* Release */, 495 | ); 496 | defaultConfigurationIsVisible = 0; 497 | defaultConfigurationName = Release; 498 | }; 499 | /* End XCConfigurationList section */ 500 | }; 501 | rootObject = 0B3ABB0B1D6DF12400479F1D /* Project object */; 502 | } 503 | -------------------------------------------------------------------------------- /StickyHeader.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /StickyHeader.xcodeproj/xcshareddata/xcschemes/StickyHeader.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /StickyHeader.xcodeproj/xcuserdata/yheinrich.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | StickyHeader.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | TestApp.xcscheme 13 | 14 | orderHint 15 | 2 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 0B3ABB131D6DF12400479F1D 21 | 22 | primary 23 | 24 | 25 | 0BD75F581D6F347200A2E6CD 26 | 27 | primary 28 | 29 | 30 | 0BD75F6E1D6F348200A2E6CD 31 | 32 | primary 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /StickyHeader/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 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /StickyHeader/StickyHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // StickyHeader.h 3 | // StickyHeader 4 | // 5 | // Created by Yannick Heinrich on 24.08.16. 6 | // Copyright © 2016 yageek. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for StickyHeader. 12 | FOUNDATION_EXPORT double StickyHeaderVersionNumber; 13 | 14 | //! Project version string for StickyHeader. 15 | FOUNDATION_EXPORT const unsigned char StickyHeaderVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /StickyHeader/StickyHeader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StickyHeader.swift 3 | // StickyHeader 4 | // 5 | // Created by Yannick Heinrich on 24.08.16. 6 | // Copyright © 2016 yageek. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /** 12 | The class managing the sticky header behaviour. 13 | */ 14 | public class StickyHeader: NSObject { 15 | 16 | /** 17 | The view containing the provided header. 18 | */ 19 | private(set) lazy var contentView: StickyHeaderView = { 20 | let view = StickyHeaderView() 21 | view.parent = self 22 | view.clipsToBounds = true 23 | return view 24 | }() 25 | 26 | private weak var _scrollView: UIScrollView? 27 | 28 | /** 29 | The `UIScrollView` attached to the sticky header. 30 | */ 31 | public weak var scrollView: UIScrollView? { 32 | get { 33 | return _scrollView 34 | } 35 | 36 | set { 37 | if _scrollView != newValue { 38 | _scrollView = newValue 39 | 40 | if let scrollView = scrollView { 41 | self.adjustScrollViewTopInset(top: scrollView.contentInset.top + self.height) 42 | scrollView.addSubview(self.contentView) 43 | } 44 | 45 | self.layoutContentView() 46 | } 47 | } 48 | } 49 | 50 | private var _view: UIView? 51 | 52 | /** 53 | The `UIScrollView attached to the sticky header. 54 | */ 55 | public var view: UIView? { 56 | set { 57 | guard newValue != _view else { return } 58 | _view = newValue 59 | updateConstraints() 60 | } 61 | get { 62 | return _view 63 | } 64 | } 65 | 66 | private var _height: CGFloat = 0 67 | 68 | /** 69 | The height of the header. 70 | */ 71 | public var height: CGFloat { 72 | get { return _height } 73 | set { 74 | guard newValue != _height else { return } 75 | 76 | if let scrollView = self.scrollView { 77 | self.adjustScrollViewTopInset(top: scrollView.contentInset.top - height + newValue) 78 | } 79 | 80 | _height = newValue 81 | 82 | self.updateConstraints() 83 | self.layoutContentView() 84 | 85 | } 86 | } 87 | private var _minimumHeight: CGFloat = 0 88 | 89 | /** 90 | The minimum height of the header. 91 | */ 92 | public var minimumHeight: CGFloat { 93 | get { return _minimumHeight } 94 | set { 95 | _minimumHeight = newValue 96 | layoutContentView() 97 | } 98 | } 99 | 100 | private func adjustScrollViewTopInset(top: CGFloat) { 101 | 102 | guard let scrollView = self.scrollView else { return } 103 | var inset = scrollView.contentInset 104 | 105 | //Adjust content offset 106 | var offset = scrollView.contentOffset 107 | offset.y += inset.top - top 108 | scrollView.contentOffset = offset 109 | 110 | //Adjust content inset 111 | inset.top = top 112 | scrollView.contentInset = inset 113 | 114 | self.scrollView = scrollView 115 | } 116 | private func updateConstraints() { 117 | guard let view = self.view else { return } 118 | 119 | view.removeFromSuperview() 120 | self.contentView.addSubview(view) 121 | 122 | view.translatesAutoresizingMaskIntoConstraints = false 123 | 124 | self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[v]|", options: [], metrics: nil, views: ["v": view])) 125 | 126 | self.contentView.addConstraint(NSLayoutConstraint(item: view, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1, constant: 0)) 127 | 128 | self.contentView.addConstraint(NSLayoutConstraint(item: view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: self.height)) 129 | 130 | } 131 | 132 | private func layoutContentView() { 133 | var relativeYOffset: CGFloat = 0 134 | 135 | guard let scrollView = self.scrollView else { return } 136 | 137 | if scrollView.contentOffset.y < -self.minimumHeight { 138 | relativeYOffset = -self.height 139 | } else { 140 | 141 | let compensation: CGFloat = -self.minimumHeight - scrollView.contentOffset.y 142 | relativeYOffset = -self.height - compensation 143 | } 144 | 145 | let frame = CGRect(x: 0, y: relativeYOffset, width: scrollView.frame.size.width, height: height) 146 | 147 | self.contentView.frame = frame 148 | } 149 | 150 | 151 | public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { 152 | if let path = keyPath, context == &StickyHeaderView.KVOContext && path == "contentOffset" { 153 | self.layoutContentView() 154 | } else { 155 | super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) 156 | } 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /StickyHeader/StickyHeaderView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StickyHeaderView.swift 3 | // StickyHeader 4 | // 5 | // Created by Yannick Heinrich on 24.08.16. 6 | // Copyright © 2016 yageek. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | internal class StickyHeaderView: UIView { 12 | weak var parent: StickyHeader? 13 | 14 | internal static var KVOContext = 0 15 | 16 | override func willMove(toSuperview view: UIView?) { 17 | if let view = self.superview, view.isKind(of:UIScrollView.self), let parent = self.parent { 18 | view.removeObserver(parent, forKeyPath: "contentOffset", context: &StickyHeaderView.KVOContext) 19 | } 20 | } 21 | 22 | override func didMoveToSuperview() { 23 | if let view = self.superview, view.isKind(of:UIScrollView.self), let parent = parent { 24 | view.addObserver(parent, forKeyPath: "contentOffset", options: .new, context: &StickyHeaderView.KVOContext) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /StickyHeader/UIScrollViewExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollViewExtension.swift 3 | // StickyHeader 4 | // 5 | // Created by Yannick Heinrich on 25.08.16. 6 | // Copyright © 2016 yageek. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ObjectiveC 11 | 12 | private var xoStickyHeaderKey: UInt8 = 0 13 | 14 | public extension UIScrollView { 15 | 16 | public var stickyHeader: StickyHeader! { 17 | 18 | get { 19 | 20 | var header = objc_getAssociatedObject(self, &xoStickyHeaderKey) as? StickyHeader 21 | 22 | if header == nil { 23 | header = StickyHeader() 24 | header!.scrollView = self 25 | objc_setAssociatedObject(self, &xoStickyHeaderKey, header, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 26 | } 27 | 28 | return header! 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /TestApp/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // TestApp 4 | // 5 | // Created by Yannick Heinrich on 25.08.16. 6 | // Copyright © 2016 yageek. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /TestApp/Assets.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 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /TestApp/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 | -------------------------------------------------------------------------------- /TestApp/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 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /TestApp/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /TestApp/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // StickyHeader 4 | // 5 | // Created by Yannick Heinrich on 25.08.16. 6 | // Copyright © 2016 yageek. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import StickyHeader 11 | 12 | class ViewController: UICollectionViewController { 13 | 14 | 15 | let headerView: UIView = { 16 | 17 | let view = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 100)) 18 | view.backgroundColor = UIColor.blue 19 | view.translatesAutoresizingMaskIntoConstraints = false 20 | return view 21 | }() 22 | 23 | override func viewDidLoad() { 24 | super.viewDidLoad() 25 | 26 | self.collectionView?.stickyHeader.view = self.headerView 27 | self.collectionView?.stickyHeader.height = 200 28 | self.collectionView?.stickyHeader.minimumHeight = 100 29 | 30 | } 31 | 32 | override func didReceiveMemoryWarning() { 33 | super.didReceiveMemoryWarning() 34 | // Dispose of any resources that can be recreated. 35 | } 36 | 37 | override func numberOfSections(in collectionView: UICollectionView) -> Int { 38 | return 1 39 | } 40 | 41 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 42 | return 1000 43 | } 44 | 45 | override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 46 | return collectionView.dequeueReusableCell(withReuseIdentifier:"Cell", for: indexPath) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /TestApp/ViewControllerTwo.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewControllerTwo.swift 3 | // StickyHeader 4 | // 5 | // Created by Yannick Heinrich on 26.08.16. 6 | // Copyright © 2016 yageek. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewControllerTwo: UITableViewController { 12 | let headerView: UIView = { 13 | 14 | let view = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 100)) 15 | view.backgroundColor = UIColor.blue 16 | view.translatesAutoresizingMaskIntoConstraints = false 17 | return view 18 | }() 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | 23 | self.tableView.stickyHeader.view = self.headerView 24 | self.tableView.stickyHeader.height = 200 25 | self.tableView.stickyHeader.minimumHeight = 100 26 | } 27 | 28 | // MARK: - Table view data source 29 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 30 | return 1000 31 | } 32 | 33 | 34 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 35 | let cell = tableView.dequeueReusableCell(withIdentifier:"Cell", for: indexPath) 36 | return cell 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /TestApp/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yageek/StickyHeader/79b5157abc637b3104f21e61ad2402aa134381c4/TestApp/demo.gif --------------------------------------------------------------------------------