├── .gitignore ├── LICENSE ├── PDPullToRefresh.podspec ├── PDPullToRefresh.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── PDPullToRefresh ├── Classes │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── ViewController.h │ └── ViewController.m ├── PDPullToRefresh │ ├── PDPullToRefresh.h │ ├── UIScrollView+PDFooterRefreshView.h │ ├── UIScrollView+PDFooterRefreshView.m │ ├── UIScrollView+PDHeaderRefreshView.h │ └── UIScrollView+PDHeaderRefreshView.m └── Supporting Files │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── main.m ├── PDPullToRefreshTests ├── Info.plist └── PDPullToRefreshTests.m └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 panda 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 | -------------------------------------------------------------------------------- /PDPullToRefresh.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'PDPullToRefresh' 3 | s.version = '1.0.0' 4 | s.license = 'MIT' 5 | s.summary = 'An easy way to use pull-to-refresh.' 6 | s.homepage = 'https://github.com/v2panda/PDPullToRefresh' 7 | s.authors = { 'v2panda' => 'pdxuzhen@gmail.com' } 8 | s.source = { :git => 'https://github.com/v2panda/PDPullToRefresh.git', :tag => s.version.to_s } 9 | s.requires_arc = true 10 | s.ios.deployment_target = '8.0' 11 | s.source_files = 'PDPullToRefresh/PDPullToRefresh/*.{h,m}' 12 | end 13 | -------------------------------------------------------------------------------- /PDPullToRefresh.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2840F4181C4B4773007A037E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2840F4171C4B4773007A037E /* main.m */; }; 11 | 2840F41B1C4B4773007A037E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2840F41A1C4B4773007A037E /* AppDelegate.m */; }; 12 | 2840F41E1C4B4773007A037E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2840F41D1C4B4773007A037E /* ViewController.m */; }; 13 | 2840F4211C4B4773007A037E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2840F41F1C4B4773007A037E /* Main.storyboard */; }; 14 | 2840F4231C4B4773007A037E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2840F4221C4B4773007A037E /* Assets.xcassets */; }; 15 | 2840F4261C4B4773007A037E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2840F4241C4B4773007A037E /* LaunchScreen.storyboard */; }; 16 | 2840F4311C4B4773007A037E /* PDPullToRefreshTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2840F4301C4B4773007A037E /* PDPullToRefreshTests.m */; }; 17 | 2840F4421C4B48EC007A037E /* UIScrollView+PDFooterRefreshView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2840F43F1C4B48EC007A037E /* UIScrollView+PDFooterRefreshView.m */; }; 18 | 2840F4431C4B48EC007A037E /* UIScrollView+PDHeaderRefreshView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2840F4411C4B48EC007A037E /* UIScrollView+PDHeaderRefreshView.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 2840F42D1C4B4773007A037E /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 2840F40B1C4B4773007A037E /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 2840F4121C4B4773007A037E; 27 | remoteInfo = PDPullToRefresh; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 2840F4131C4B4773007A037E /* PDPullToRefresh.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PDPullToRefresh.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 2840F4171C4B4773007A037E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 34 | 2840F4191C4B4773007A037E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 35 | 2840F41A1C4B4773007A037E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 36 | 2840F41C1C4B4773007A037E /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 37 | 2840F41D1C4B4773007A037E /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 38 | 2840F4201C4B4773007A037E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 39 | 2840F4221C4B4773007A037E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | 2840F4251C4B4773007A037E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 41 | 2840F4271C4B4773007A037E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | 2840F42C1C4B4773007A037E /* PDPullToRefreshTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PDPullToRefreshTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 2840F4301C4B4773007A037E /* PDPullToRefreshTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PDPullToRefreshTests.m; sourceTree = ""; }; 44 | 2840F4321C4B4773007A037E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 2840F43D1C4B48EC007A037E /* PDPullToRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDPullToRefresh.h; sourceTree = ""; }; 46 | 2840F43E1C4B48EC007A037E /* UIScrollView+PDFooterRefreshView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+PDFooterRefreshView.h"; sourceTree = ""; }; 47 | 2840F43F1C4B48EC007A037E /* UIScrollView+PDFooterRefreshView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+PDFooterRefreshView.m"; sourceTree = ""; }; 48 | 2840F4401C4B48EC007A037E /* UIScrollView+PDHeaderRefreshView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+PDHeaderRefreshView.h"; sourceTree = ""; }; 49 | 2840F4411C4B48EC007A037E /* UIScrollView+PDHeaderRefreshView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+PDHeaderRefreshView.m"; sourceTree = ""; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 2840F4101C4B4773007A037E /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | 2840F4291C4B4773007A037E /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | /* End PBXFrameworksBuildPhase section */ 68 | 69 | /* Begin PBXGroup section */ 70 | 2840F40A1C4B4773007A037E = { 71 | isa = PBXGroup; 72 | children = ( 73 | 2840F4151C4B4773007A037E /* PDPullToRefresh */, 74 | 2840F42F1C4B4773007A037E /* PDPullToRefreshTests */, 75 | 2840F4141C4B4773007A037E /* Products */, 76 | ); 77 | sourceTree = ""; 78 | }; 79 | 2840F4141C4B4773007A037E /* Products */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 2840F4131C4B4773007A037E /* PDPullToRefresh.app */, 83 | 2840F42C1C4B4773007A037E /* PDPullToRefreshTests.xctest */, 84 | ); 85 | name = Products; 86 | sourceTree = ""; 87 | }; 88 | 2840F4151C4B4773007A037E /* PDPullToRefresh */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 2840F43B1C4B48BE007A037E /* Classes */, 92 | 2840F43C1C4B48EC007A037E /* PDPullToRefresh */, 93 | 2840F4161C4B4773007A037E /* Supporting Files */, 94 | ); 95 | path = PDPullToRefresh; 96 | sourceTree = ""; 97 | }; 98 | 2840F4161C4B4773007A037E /* Supporting Files */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 2840F4221C4B4773007A037E /* Assets.xcassets */, 102 | 2840F4271C4B4773007A037E /* Info.plist */, 103 | 2840F4241C4B4773007A037E /* LaunchScreen.storyboard */, 104 | 2840F41F1C4B4773007A037E /* Main.storyboard */, 105 | 2840F4171C4B4773007A037E /* main.m */, 106 | ); 107 | path = "Supporting Files"; 108 | sourceTree = ""; 109 | }; 110 | 2840F42F1C4B4773007A037E /* PDPullToRefreshTests */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 2840F4321C4B4773007A037E /* Info.plist */, 114 | 2840F4301C4B4773007A037E /* PDPullToRefreshTests.m */, 115 | ); 116 | path = PDPullToRefreshTests; 117 | sourceTree = ""; 118 | }; 119 | 2840F43B1C4B48BE007A037E /* Classes */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 2840F4191C4B4773007A037E /* AppDelegate.h */, 123 | 2840F41A1C4B4773007A037E /* AppDelegate.m */, 124 | 2840F41C1C4B4773007A037E /* ViewController.h */, 125 | 2840F41D1C4B4773007A037E /* ViewController.m */, 126 | ); 127 | path = Classes; 128 | sourceTree = ""; 129 | }; 130 | 2840F43C1C4B48EC007A037E /* PDPullToRefresh */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | 2840F43D1C4B48EC007A037E /* PDPullToRefresh.h */, 134 | 2840F43E1C4B48EC007A037E /* UIScrollView+PDFooterRefreshView.h */, 135 | 2840F43F1C4B48EC007A037E /* UIScrollView+PDFooterRefreshView.m */, 136 | 2840F4401C4B48EC007A037E /* UIScrollView+PDHeaderRefreshView.h */, 137 | 2840F4411C4B48EC007A037E /* UIScrollView+PDHeaderRefreshView.m */, 138 | ); 139 | path = PDPullToRefresh; 140 | sourceTree = ""; 141 | }; 142 | /* End PBXGroup section */ 143 | 144 | /* Begin PBXNativeTarget section */ 145 | 2840F4121C4B4773007A037E /* PDPullToRefresh */ = { 146 | isa = PBXNativeTarget; 147 | buildConfigurationList = 2840F4351C4B4773007A037E /* Build configuration list for PBXNativeTarget "PDPullToRefresh" */; 148 | buildPhases = ( 149 | 2840F40F1C4B4773007A037E /* Sources */, 150 | 2840F4101C4B4773007A037E /* Frameworks */, 151 | 2840F4111C4B4773007A037E /* Resources */, 152 | ); 153 | buildRules = ( 154 | ); 155 | dependencies = ( 156 | ); 157 | name = PDPullToRefresh; 158 | productName = PDPullToRefresh; 159 | productReference = 2840F4131C4B4773007A037E /* PDPullToRefresh.app */; 160 | productType = "com.apple.product-type.application"; 161 | }; 162 | 2840F42B1C4B4773007A037E /* PDPullToRefreshTests */ = { 163 | isa = PBXNativeTarget; 164 | buildConfigurationList = 2840F4381C4B4773007A037E /* Build configuration list for PBXNativeTarget "PDPullToRefreshTests" */; 165 | buildPhases = ( 166 | 2840F4281C4B4773007A037E /* Sources */, 167 | 2840F4291C4B4773007A037E /* Frameworks */, 168 | 2840F42A1C4B4773007A037E /* Resources */, 169 | ); 170 | buildRules = ( 171 | ); 172 | dependencies = ( 173 | 2840F42E1C4B4773007A037E /* PBXTargetDependency */, 174 | ); 175 | name = PDPullToRefreshTests; 176 | productName = PDPullToRefreshTests; 177 | productReference = 2840F42C1C4B4773007A037E /* PDPullToRefreshTests.xctest */; 178 | productType = "com.apple.product-type.bundle.unit-test"; 179 | }; 180 | /* End PBXNativeTarget section */ 181 | 182 | /* Begin PBXProject section */ 183 | 2840F40B1C4B4773007A037E /* Project object */ = { 184 | isa = PBXProject; 185 | attributes = { 186 | LastUpgradeCheck = 0720; 187 | ORGANIZATIONNAME = v2panda; 188 | TargetAttributes = { 189 | 2840F4121C4B4773007A037E = { 190 | CreatedOnToolsVersion = 7.2; 191 | }; 192 | 2840F42B1C4B4773007A037E = { 193 | CreatedOnToolsVersion = 7.2; 194 | TestTargetID = 2840F4121C4B4773007A037E; 195 | }; 196 | }; 197 | }; 198 | buildConfigurationList = 2840F40E1C4B4773007A037E /* Build configuration list for PBXProject "PDPullToRefresh" */; 199 | compatibilityVersion = "Xcode 3.2"; 200 | developmentRegion = English; 201 | hasScannedForEncodings = 0; 202 | knownRegions = ( 203 | en, 204 | Base, 205 | ); 206 | mainGroup = 2840F40A1C4B4773007A037E; 207 | productRefGroup = 2840F4141C4B4773007A037E /* Products */; 208 | projectDirPath = ""; 209 | projectRoot = ""; 210 | targets = ( 211 | 2840F4121C4B4773007A037E /* PDPullToRefresh */, 212 | 2840F42B1C4B4773007A037E /* PDPullToRefreshTests */, 213 | ); 214 | }; 215 | /* End PBXProject section */ 216 | 217 | /* Begin PBXResourcesBuildPhase section */ 218 | 2840F4111C4B4773007A037E /* Resources */ = { 219 | isa = PBXResourcesBuildPhase; 220 | buildActionMask = 2147483647; 221 | files = ( 222 | 2840F4261C4B4773007A037E /* LaunchScreen.storyboard in Resources */, 223 | 2840F4231C4B4773007A037E /* Assets.xcassets in Resources */, 224 | 2840F4211C4B4773007A037E /* Main.storyboard in Resources */, 225 | ); 226 | runOnlyForDeploymentPostprocessing = 0; 227 | }; 228 | 2840F42A1C4B4773007A037E /* Resources */ = { 229 | isa = PBXResourcesBuildPhase; 230 | buildActionMask = 2147483647; 231 | files = ( 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | }; 235 | /* End PBXResourcesBuildPhase section */ 236 | 237 | /* Begin PBXSourcesBuildPhase section */ 238 | 2840F40F1C4B4773007A037E /* Sources */ = { 239 | isa = PBXSourcesBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | 2840F41E1C4B4773007A037E /* ViewController.m in Sources */, 243 | 2840F4421C4B48EC007A037E /* UIScrollView+PDFooterRefreshView.m in Sources */, 244 | 2840F41B1C4B4773007A037E /* AppDelegate.m in Sources */, 245 | 2840F4181C4B4773007A037E /* main.m in Sources */, 246 | 2840F4431C4B48EC007A037E /* UIScrollView+PDHeaderRefreshView.m in Sources */, 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | }; 250 | 2840F4281C4B4773007A037E /* Sources */ = { 251 | isa = PBXSourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | 2840F4311C4B4773007A037E /* PDPullToRefreshTests.m in Sources */, 255 | ); 256 | runOnlyForDeploymentPostprocessing = 0; 257 | }; 258 | /* End PBXSourcesBuildPhase section */ 259 | 260 | /* Begin PBXTargetDependency section */ 261 | 2840F42E1C4B4773007A037E /* PBXTargetDependency */ = { 262 | isa = PBXTargetDependency; 263 | target = 2840F4121C4B4773007A037E /* PDPullToRefresh */; 264 | targetProxy = 2840F42D1C4B4773007A037E /* PBXContainerItemProxy */; 265 | }; 266 | /* End PBXTargetDependency section */ 267 | 268 | /* Begin PBXVariantGroup section */ 269 | 2840F41F1C4B4773007A037E /* Main.storyboard */ = { 270 | isa = PBXVariantGroup; 271 | children = ( 272 | 2840F4201C4B4773007A037E /* Base */, 273 | ); 274 | name = Main.storyboard; 275 | path = .; 276 | sourceTree = ""; 277 | }; 278 | 2840F4241C4B4773007A037E /* LaunchScreen.storyboard */ = { 279 | isa = PBXVariantGroup; 280 | children = ( 281 | 2840F4251C4B4773007A037E /* Base */, 282 | ); 283 | name = LaunchScreen.storyboard; 284 | path = .; 285 | sourceTree = ""; 286 | }; 287 | /* End PBXVariantGroup section */ 288 | 289 | /* Begin XCBuildConfiguration section */ 290 | 2840F4331C4B4773007A037E /* Debug */ = { 291 | isa = XCBuildConfiguration; 292 | buildSettings = { 293 | ALWAYS_SEARCH_USER_PATHS = NO; 294 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 295 | CLANG_CXX_LIBRARY = "libc++"; 296 | CLANG_ENABLE_MODULES = YES; 297 | CLANG_ENABLE_OBJC_ARC = YES; 298 | CLANG_WARN_BOOL_CONVERSION = YES; 299 | CLANG_WARN_CONSTANT_CONVERSION = YES; 300 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 301 | CLANG_WARN_EMPTY_BODY = YES; 302 | CLANG_WARN_ENUM_CONVERSION = YES; 303 | CLANG_WARN_INT_CONVERSION = YES; 304 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 305 | CLANG_WARN_UNREACHABLE_CODE = YES; 306 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 307 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 308 | COPY_PHASE_STRIP = NO; 309 | DEBUG_INFORMATION_FORMAT = dwarf; 310 | ENABLE_STRICT_OBJC_MSGSEND = YES; 311 | ENABLE_TESTABILITY = YES; 312 | GCC_C_LANGUAGE_STANDARD = gnu99; 313 | GCC_DYNAMIC_NO_PIC = NO; 314 | GCC_NO_COMMON_BLOCKS = YES; 315 | GCC_OPTIMIZATION_LEVEL = 0; 316 | GCC_PREPROCESSOR_DEFINITIONS = ( 317 | "DEBUG=1", 318 | "$(inherited)", 319 | ); 320 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 321 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 322 | GCC_WARN_UNDECLARED_SELECTOR = YES; 323 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 324 | GCC_WARN_UNUSED_FUNCTION = YES; 325 | GCC_WARN_UNUSED_VARIABLE = YES; 326 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 327 | MTL_ENABLE_DEBUG_INFO = YES; 328 | ONLY_ACTIVE_ARCH = YES; 329 | SDKROOT = iphoneos; 330 | TARGETED_DEVICE_FAMILY = "1,2"; 331 | }; 332 | name = Debug; 333 | }; 334 | 2840F4341C4B4773007A037E /* Release */ = { 335 | isa = XCBuildConfiguration; 336 | buildSettings = { 337 | ALWAYS_SEARCH_USER_PATHS = NO; 338 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 339 | CLANG_CXX_LIBRARY = "libc++"; 340 | CLANG_ENABLE_MODULES = YES; 341 | CLANG_ENABLE_OBJC_ARC = YES; 342 | CLANG_WARN_BOOL_CONVERSION = YES; 343 | CLANG_WARN_CONSTANT_CONVERSION = YES; 344 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 345 | CLANG_WARN_EMPTY_BODY = YES; 346 | CLANG_WARN_ENUM_CONVERSION = YES; 347 | CLANG_WARN_INT_CONVERSION = YES; 348 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 349 | CLANG_WARN_UNREACHABLE_CODE = YES; 350 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 351 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 352 | COPY_PHASE_STRIP = NO; 353 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 354 | ENABLE_NS_ASSERTIONS = NO; 355 | ENABLE_STRICT_OBJC_MSGSEND = YES; 356 | GCC_C_LANGUAGE_STANDARD = gnu99; 357 | GCC_NO_COMMON_BLOCKS = YES; 358 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 359 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 360 | GCC_WARN_UNDECLARED_SELECTOR = YES; 361 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 362 | GCC_WARN_UNUSED_FUNCTION = YES; 363 | GCC_WARN_UNUSED_VARIABLE = YES; 364 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 365 | MTL_ENABLE_DEBUG_INFO = NO; 366 | SDKROOT = iphoneos; 367 | TARGETED_DEVICE_FAMILY = "1,2"; 368 | VALIDATE_PRODUCT = YES; 369 | }; 370 | name = Release; 371 | }; 372 | 2840F4361C4B4773007A037E /* Debug */ = { 373 | isa = XCBuildConfiguration; 374 | buildSettings = { 375 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 376 | INFOPLIST_FILE = "PDPullToRefresh/Supporting Files/Info.plist"; 377 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 378 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 379 | PRODUCT_BUNDLE_IDENTIFIER = PDA.PDPullToRefresh; 380 | PRODUCT_NAME = "$(TARGET_NAME)"; 381 | }; 382 | name = Debug; 383 | }; 384 | 2840F4371C4B4773007A037E /* Release */ = { 385 | isa = XCBuildConfiguration; 386 | buildSettings = { 387 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 388 | INFOPLIST_FILE = "PDPullToRefresh/Supporting Files/Info.plist"; 389 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 390 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 391 | PRODUCT_BUNDLE_IDENTIFIER = PDA.PDPullToRefresh; 392 | PRODUCT_NAME = "$(TARGET_NAME)"; 393 | }; 394 | name = Release; 395 | }; 396 | 2840F4391C4B4773007A037E /* Debug */ = { 397 | isa = XCBuildConfiguration; 398 | buildSettings = { 399 | BUNDLE_LOADER = "$(TEST_HOST)"; 400 | INFOPLIST_FILE = PDPullToRefreshTests/Info.plist; 401 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 402 | PRODUCT_BUNDLE_IDENTIFIER = PDA.PDPullToRefreshTests; 403 | PRODUCT_NAME = "$(TARGET_NAME)"; 404 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PDPullToRefresh.app/PDPullToRefresh"; 405 | }; 406 | name = Debug; 407 | }; 408 | 2840F43A1C4B4773007A037E /* Release */ = { 409 | isa = XCBuildConfiguration; 410 | buildSettings = { 411 | BUNDLE_LOADER = "$(TEST_HOST)"; 412 | INFOPLIST_FILE = PDPullToRefreshTests/Info.plist; 413 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 414 | PRODUCT_BUNDLE_IDENTIFIER = PDA.PDPullToRefreshTests; 415 | PRODUCT_NAME = "$(TARGET_NAME)"; 416 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PDPullToRefresh.app/PDPullToRefresh"; 417 | }; 418 | name = Release; 419 | }; 420 | /* End XCBuildConfiguration section */ 421 | 422 | /* Begin XCConfigurationList section */ 423 | 2840F40E1C4B4773007A037E /* Build configuration list for PBXProject "PDPullToRefresh" */ = { 424 | isa = XCConfigurationList; 425 | buildConfigurations = ( 426 | 2840F4331C4B4773007A037E /* Debug */, 427 | 2840F4341C4B4773007A037E /* Release */, 428 | ); 429 | defaultConfigurationIsVisible = 0; 430 | defaultConfigurationName = Release; 431 | }; 432 | 2840F4351C4B4773007A037E /* Build configuration list for PBXNativeTarget "PDPullToRefresh" */ = { 433 | isa = XCConfigurationList; 434 | buildConfigurations = ( 435 | 2840F4361C4B4773007A037E /* Debug */, 436 | 2840F4371C4B4773007A037E /* Release */, 437 | ); 438 | defaultConfigurationIsVisible = 0; 439 | defaultConfigurationName = Release; 440 | }; 441 | 2840F4381C4B4773007A037E /* Build configuration list for PBXNativeTarget "PDPullToRefreshTests" */ = { 442 | isa = XCConfigurationList; 443 | buildConfigurations = ( 444 | 2840F4391C4B4773007A037E /* Debug */, 445 | 2840F43A1C4B4773007A037E /* Release */, 446 | ); 447 | defaultConfigurationIsVisible = 0; 448 | defaultConfigurationName = Release; 449 | }; 450 | /* End XCConfigurationList section */ 451 | }; 452 | rootObject = 2840F40B1C4B4773007A037E /* Project object */; 453 | } 454 | -------------------------------------------------------------------------------- /PDPullToRefresh.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PDPullToRefresh/Classes/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // PDPullToRefresh 4 | // 5 | // Created by Panda on 16/1/17. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /PDPullToRefresh/Classes/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // PDPullToRefresh 4 | // 5 | // Created by Panda on 16/1/17. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | [UITableView appearance].tableFooterView = [UIView new]; 21 | return YES; 22 | } 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // 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. 27 | } 28 | 29 | - (void)applicationDidEnterBackground:(UIApplication *)application { 30 | // 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. 31 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 32 | } 33 | 34 | - (void)applicationWillEnterForeground:(UIApplication *)application { 35 | // 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. 36 | } 37 | 38 | - (void)applicationDidBecomeActive:(UIApplication *)application { 39 | // 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. 40 | } 41 | 42 | - (void)applicationWillTerminate:(UIApplication *)application { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /PDPullToRefresh/Classes/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // PDPullToRefresh 4 | // 5 | // Created by Panda on 16/1/17. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /PDPullToRefresh/Classes/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // PDPullToRefresh 4 | // 5 | // Created by Panda on 16/1/17. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "PDPullToRefresh.h" 11 | 12 | @interface ViewController () 13 | 14 | @property (nonatomic, strong) UITableView *tableView; 15 | 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | 23 | [self initUI]; 24 | 25 | [self addPDRefresh]; 26 | } 27 | 28 | - (void)addPDRefresh { 29 | [self.tableView pd_addHeaderRefreshWithNavigationBar:YES andActionHandler:^{ 30 | double delayInSeconds = 3.0; 31 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 32 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 33 | NSLog(@"Header - ActionHandler"); 34 | [self.tableView.pdHeaderRefreshView stopRefreshing]; 35 | }); 36 | }]; 37 | 38 | [self.tableView pd_addFooterRefreshWithNavigationBar:YES andActionHandler:^{ 39 | double delayInSeconds = 3.0; 40 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 41 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 42 | NSLog(@"Footer - ActionHandler"); 43 | [self.tableView.pdFooterRefreshView stopRefreshing]; 44 | }); 45 | }]; 46 | } 47 | 48 | - (void)initUI { 49 | [self.view addSubview:self.tableView]; 50 | } 51 | 52 | #pragma mark UITableViewDataSource 53 | 54 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 55 | return 15; 56 | } 57 | 58 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 59 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell" 60 | forIndexPath:indexPath]; 61 | cell.textLabel.text = [NSString stringWithFormat:@"第%ld条",(long)indexPath.row]; 62 | return cell; 63 | } 64 | 65 | #pragma mark getter&setter 66 | 67 | - (UITableView *)tableView { 68 | if (!_tableView) { 69 | _tableView = [[UITableView alloc]initWithFrame:self.view.bounds]; 70 | _tableView.dataSource = self; 71 | [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"TableViewCell"]; 72 | } 73 | return _tableView; 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /PDPullToRefresh/PDPullToRefresh/PDPullToRefresh.h: -------------------------------------------------------------------------------- 1 | // 2 | // PDPullToRefresh.h 3 | // PDPullToRefreshDemo 4 | // 5 | // Created by Panda on 16/1/12. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #ifndef PDPullToRefresh_h 10 | #define PDPullToRefresh_h 11 | 12 | #import "UIScrollView+PDHeaderRefreshView.h" 13 | #import "UIScrollView+PDFooterRefreshView.h" 14 | 15 | 16 | #endif /* PDPullToRefresh_h */ 17 | -------------------------------------------------------------------------------- /PDPullToRefresh/PDPullToRefresh/UIScrollView+PDFooterRefreshView.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+PDFooterRefreshView.h 3 | // PDPullToRefreshDemo 4 | // 5 | // Created by Panda on 16/1/15. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ActionHandler)(void); 12 | 13 | @class PDFooterRefreshView; 14 | @interface UIScrollView (PDFooterRefreshView) 15 | 16 | /** 17 | * 下拉滑动距离 - 下拉View的高 18 | * Default is 80 19 | */ 20 | @property (nonatomic, assign) CGFloat pdFooterRefreshViewHeight; 21 | 22 | /** 23 | * 上拉刷新View 24 | */ 25 | @property (nonatomic, strong) PDFooterRefreshView *pdFooterRefreshView; 26 | 27 | /** 28 | * 添加刷新 29 | * 30 | * @param actionHandler 回调 31 | */ 32 | - (void)pd_addFooterRefreshWithNavigationBar:(BOOL)navBar 33 | andActionHandler:(ActionHandler)actionHandler; 34 | 35 | @end 36 | 37 | @interface PDFooterRefreshView : UIView 38 | 39 | - (instancetype)initWithAssociatedScrollView:(UIScrollView *)scrollView 40 | withNavigationBar:(BOOL)navBar 41 | andRefreshViewHeight:(CGFloat)refreshViewHeight 42 | andActionHandler:(ActionHandler)actionHandler; 43 | 44 | /** 45 | * 停止刷新 46 | */ 47 | - (void)stopRefreshing; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /PDPullToRefresh/PDPullToRefresh/UIScrollView+PDFooterRefreshView.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+PDFooterRefreshView.m 3 | // PDPullToRefreshDemo 4 | // 5 | // Created by Panda on 16/1/15. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import "UIScrollView+PDFooterRefreshView.h" 10 | #import 11 | #import 12 | #import 13 | 14 | static char UIScrollViewPDFooterRefreshView; 15 | static char PDFooterRefreshViewHeight; 16 | 17 | @implementation UIScrollView (PDFooterRefreshView) 18 | - (void)setPdFooterRefreshView:(PDFooterRefreshView *)pdFooterRefreshView { 19 | objc_setAssociatedObject(self, &UIScrollViewPDFooterRefreshView, pdFooterRefreshView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 20 | } 21 | 22 | - (PDFooterRefreshView *)pdFooterRefreshView { 23 | return objc_getAssociatedObject(self, &UIScrollViewPDFooterRefreshView); 24 | } 25 | 26 | - (void)setPdFooterRefreshViewHeight:(CGFloat)pdFooterRefreshViewHeight { 27 | objc_setAssociatedObject(self, &PDFooterRefreshViewHeight, @(MAX(0, pdFooterRefreshViewHeight)), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 28 | } 29 | 30 | - (CGFloat)pdFooterRefreshViewHeight { 31 | #if CGFLOAT_IS_DOUBLE 32 | return [objc_getAssociatedObject(self, &PDFooterRefreshViewHeight) doubleValue]; 33 | #else 34 | return [objc_getAssociatedObject(self, &PDFooterRefreshViewHeight) floatValue]; 35 | #endif 36 | } 37 | 38 | - (void)pd_addFooterRefreshWithNavigationBar:(BOOL)navBar 39 | andActionHandler:(ActionHandler)actionHandler { 40 | if (!self.pdFooterRefreshViewHeight) { 41 | self.pdFooterRefreshViewHeight = 80; 42 | } 43 | 44 | self.pdFooterRefreshView = [[PDFooterRefreshView alloc]initWithAssociatedScrollView:self 45 | withNavigationBar:navBar 46 | andRefreshViewHeight:self.pdFooterRefreshViewHeight 47 | andActionHandler:actionHandler]; 48 | [self insertSubview:self.pdFooterRefreshView atIndex:0]; 49 | } 50 | 51 | @end 52 | 53 | @interface PDFooterRefreshView () 54 | 55 | @property (nonatomic, retain) CALayer *animationLayer; 56 | @property (nonatomic, retain) CAShapeLayer *pathLayer; 57 | @property (nonatomic, weak)UIScrollView *associatedScrollView; 58 | @property (nonatomic, assign)CGFloat progress; 59 | @property (nonatomic, copy) ActionHandler handleBlock; 60 | @property (nonatomic, assign) BOOL isFlash; 61 | @property (nonatomic, strong) CAGradientLayer *gradientLayer; 62 | @property (nonatomic, copy) NSString *animationPacing; 63 | 64 | @end 65 | 66 | /** 默认光晕循环一次的持续时间 */ 67 | static const NSTimeInterval pHaloDuration = 1.5f; 68 | 69 | /** 默认光晕宽度 */ 70 | static const CGFloat pHaloWidth = 2.5f; 71 | 72 | /** 默认字体大小 */ 73 | static const double pFontSize = 26.0f; 74 | 75 | #define pColor [[UIColor colorWithRed:234.0/255 green:84.0/255 blue:87.0/255 alpha:1] CGColor] 76 | 77 | /** 光晕动画ID */ 78 | static NSString *const kAnimationKey = @"PDFooterRefreshViewAnimationKey"; 79 | 80 | @implementation PDFooterRefreshView { 81 | CGFloat originOffset; 82 | CGSize contentSize; 83 | CGFloat PDPullToRefreshViewHeight; 84 | BOOL isShow; 85 | } 86 | 87 | - (instancetype)initWithAssociatedScrollView:(UIScrollView *)scrollView 88 | withNavigationBar:(BOOL)navBar 89 | andRefreshViewHeight:(CGFloat)refreshViewHeight 90 | andActionHandler:(ActionHandler)actionHandler { 91 | self = [super initWithFrame:CGRectMake(0, scrollView.frame.size.height, scrollView.frame.size.width, refreshViewHeight)]; 92 | if (self) { 93 | if (navBar) { 94 | originOffset = 64.0f; 95 | }else{ 96 | originOffset = 0.0f; 97 | } 98 | self.associatedScrollView = scrollView; 99 | self.handleBlock = actionHandler; 100 | PDPullToRefreshViewHeight = refreshViewHeight; 101 | 102 | [self.associatedScrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil]; 103 | [self.associatedScrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil]; 104 | self.hidden = YES; 105 | self.animationLayer = [CALayer layer]; 106 | self.animationLayer.frame = CGRectMake(0.0f, 0.0f, 107 | scrollView.frame.size.width, 108 | refreshViewHeight); 109 | [self.layer addSublayer:self.animationLayer]; 110 | isShow = NO; 111 | [self addPullAnimation]; 112 | } 113 | return self; 114 | } 115 | 116 | - (void)setProgress:(CGFloat)progress { 117 | 118 | CGFloat diff = self.associatedScrollView.contentOffset.y - (self.associatedScrollView.contentSize.height - self.associatedScrollView.bounds.size.height) - PDPullToRefreshViewHeight; 119 | self.pathLayer.strokeEnd = progress; 120 | if (diff > 0) { 121 | if (!self.associatedScrollView.tracking && !self.hidden) 122 | { 123 | if (self.isFlash) { 124 | [self addRefreshAnimation]; 125 | self.isFlash = NO; 126 | [UIView animateWithDuration:0.3 animations:^{ 127 | 128 | self.associatedScrollView.contentInset = UIEdgeInsetsMake(originOffset, 0, PDPullToRefreshViewHeight , 0); 129 | 130 | } completion:^(BOOL finished) { 131 | self.handleBlock(); 132 | }]; 133 | } 134 | 135 | } 136 | }else { 137 | if (isShow) { 138 | self.pathLayer.strokeEnd = 1.0; 139 | } 140 | } 141 | } 142 | 143 | - (void)stopRefreshing { 144 | [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 145 | self.alpha = 0.0f; 146 | self.associatedScrollView.contentInset = UIEdgeInsetsMake(originOffset, 0, 0, 0); 147 | } completion:^(BOOL finished) { 148 | self.alpha = 1.0f; 149 | [self addPullAnimation]; 150 | if (!isShow) { 151 | self.pathLayer.strokeEnd = 0.0; 152 | } 153 | [self stopAnimating]; 154 | }]; 155 | } 156 | 157 | #pragma mark - Animation Method 158 | 159 | - (CAShapeLayer *)setupDefaultLayer:(NSString *)animationString { 160 | if (self.pathLayer != nil) { 161 | [self.pathLayer removeFromSuperlayer]; 162 | self.pathLayer = nil; 163 | } 164 | 165 | CGMutablePathRef letters = CGPathCreateMutable(); 166 | 167 | CTFontRef font = CTFontCreateWithName(CFSTR("HelveticaNeue-UltraLight"), pFontSize, NULL); 168 | NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: 169 | (__bridge id)font, kCTFontAttributeName, 170 | nil]; 171 | NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:animationString 172 | attributes:attrs]; 173 | CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString); 174 | CFArrayRef runArray = CTLineGetGlyphRuns(line); 175 | 176 | // for each RUN 177 | for (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++) { 178 | // Get FONT for this run 179 | CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex); 180 | CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName); 181 | 182 | // for each GLYPH in run 183 | for (CFIndex runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++) { 184 | // get Glyph & Glyph-data 185 | CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1); 186 | CGGlyph glyph; 187 | CGPoint position; 188 | CTRunGetGlyphs(run, thisGlyphRange, &glyph); 189 | CTRunGetPositions(run, thisGlyphRange, &position); 190 | 191 | // Get PATH of outline 192 | { 193 | CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL); 194 | CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y); 195 | // CGAffineTransform t = CGAffineTransformIdentity; 196 | CGPathAddPath(letters, &t, letter); 197 | CGPathRelease(letter); 198 | } 199 | } 200 | } 201 | CFRelease(line); 202 | 203 | UIBezierPath *path = [UIBezierPath bezierPath]; 204 | [path moveToPoint:CGPointZero]; 205 | [path appendPath:[UIBezierPath bezierPathWithCGPath:letters]]; 206 | 207 | CGPathRelease(letters); 208 | CFRelease(font); 209 | 210 | CAShapeLayer *pathLayer = [CAShapeLayer layer]; 211 | pathLayer.frame = self.animationLayer.bounds; 212 | pathLayer.bounds = CGPathGetBoundingBox(path.CGPath); 213 | pathLayer.geometryFlipped = YES; 214 | pathLayer.path = path.CGPath; 215 | pathLayer.strokeColor = [UIColor colorWithRed:234.0/255 green:84.0/255 blue:87.0/255 alpha:1].CGColor; 216 | pathLayer.fillColor = nil; 217 | pathLayer.lineWidth = 1.0f; 218 | pathLayer.lineJoin = kCALineJoinBevel; 219 | 220 | return pathLayer; 221 | } 222 | 223 | - (void)addPullAnimation { 224 | // 这就是生活 225 | CAShapeLayer *pathLayer = [self setupDefaultLayer:@"C'est La Vie"]; 226 | [self.animationLayer addSublayer:pathLayer]; 227 | self.pathLayer = pathLayer; 228 | self.isFlash = YES; 229 | } 230 | 231 | - (void)addRefreshAnimation { 232 | _animationPacing = kCAMediaTimingFunctionEaseIn; 233 | 234 | // 设置渐变层参数 235 | CAGradientLayer *gradientLayer = [CAGradientLayer layer]; 236 | gradientLayer.frame = self.animationLayer.bounds; 237 | gradientLayer.startPoint = CGPointMake(- pHaloWidth, 0); 238 | gradientLayer.endPoint = CGPointMake(0, 0); 239 | gradientLayer.colors = @[(id)pColor, 240 | (id)[[UIColor whiteColor] CGColor], 241 | (id)pColor]; 242 | 243 | [self.animationLayer addSublayer:gradientLayer]; 244 | self.gradientLayer = gradientLayer; 245 | 246 | // 生活是美好的 247 | CAShapeLayer *pathLayer = [self setupDefaultLayer:@"La Vie est belle"]; 248 | self.gradientLayer.mask = pathLayer; 249 | [self startAnimating]; 250 | } 251 | 252 | /** 开启动画 */ 253 | - (void)startAnimating { 254 | static NSString *gradientStartPointKey = @"startPoint"; 255 | static NSString *gradientEndPointKey = @"endPoint"; 256 | 257 | CAGradientLayer *gradientLayer = (CAGradientLayer *)self.gradientLayer; 258 | if([gradientLayer animationForKey:kAnimationKey] == nil) { 259 | // 通过不断改变渐变的起止范围,来实现光晕效果 260 | CABasicAnimation *startPointAnimation = [CABasicAnimation animationWithKeyPath:gradientStartPointKey]; 261 | startPointAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(1.0, 0)]; 262 | startPointAnimation.timingFunction = [CAMediaTimingFunction functionWithName:_animationPacing]; 263 | 264 | CABasicAnimation *endPointAnimation = [CABasicAnimation animationWithKeyPath:gradientEndPointKey]; 265 | endPointAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(1 + pHaloWidth, 0)]; 266 | endPointAnimation.timingFunction = [CAMediaTimingFunction functionWithName:_animationPacing]; 267 | 268 | CAAnimationGroup *group = [CAAnimationGroup animation]; 269 | group.animations = @[startPointAnimation, endPointAnimation]; 270 | group.duration = pHaloDuration; 271 | group.timingFunction = [CAMediaTimingFunction functionWithName:_animationPacing]; 272 | group.repeatCount = HUGE_VALF; 273 | 274 | [gradientLayer addAnimation:group forKey:kAnimationKey]; 275 | } 276 | } 277 | 278 | /** 结束动画 */ 279 | - (void)stopAnimating { 280 | [self.gradientLayer removeFromSuperlayer]; 281 | self.gradientLayer = nil; 282 | } 283 | 284 | #pragma mark KVO 285 | - (void)observeValueForKeyPath:(NSString *)keyPath 286 | ofObject:(id)object change:(NSDictionary *)change 287 | context:(void *)context { 288 | if ([keyPath isEqualToString:@"contentSize"]) { 289 | contentSize = [[change valueForKey:NSKeyValueChangeNewKey]CGSizeValue]; 290 | if (contentSize.height > 0.0) { 291 | self.hidden = NO; 292 | } 293 | self.frame = CGRectMake(0, contentSize.height, self.associatedScrollView.frame.size.width, PDPullToRefreshViewHeight); 294 | } 295 | if (contentSize.height + PDPullToRefreshViewHeight <= self.associatedScrollView.frame.size.height) { 296 | isShow = YES; 297 | }else{ 298 | isShow = NO; 299 | } 300 | 301 | if ([keyPath isEqualToString:@"contentOffset"]) { 302 | 303 | CGPoint contentOffset = [[change objectForKey:NSKeyValueChangeNewKey]CGPointValue]; 304 | 305 | if (contentOffset.y >= (contentSize.height - self.associatedScrollView.bounds.size.height)) { 306 | 307 | self.center = CGPointMake(self.center.x, contentSize.height + (contentOffset.y - (contentSize.height - self.associatedScrollView.frame.size.height))/2); 308 | self.progress = MAX(0.0, MIN((contentOffset.y - (contentSize.height - self.associatedScrollView.frame.size.height)) / PDPullToRefreshViewHeight, 1.0)); 309 | } 310 | } 311 | } 312 | 313 | #pragma mark dealloc 314 | -(void)dealloc{ 315 | [self.associatedScrollView removeObserver:self forKeyPath:@"contentOffset"]; 316 | [self.associatedScrollView removeObserver:self forKeyPath:@"contentSize"]; 317 | } 318 | @end 319 | -------------------------------------------------------------------------------- /PDPullToRefresh/PDPullToRefresh/UIScrollView+PDHeaderRefreshView.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+PDHeaderRefreshView.h 3 | // PDPullToRefreshDemo 4 | // 5 | // Created by Panda on 16/1/15. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ActionHandler)(void); 12 | 13 | @class PDHeaderRefreshView; 14 | @interface UIScrollView (PDHeaderRefreshView) 15 | 16 | /** 17 | * 下拉滑动距离 - 下拉View的高 18 | * Default is 80 19 | */ 20 | @property (nonatomic, assign) CGFloat pdHeaderRefreshViewHeight; 21 | 22 | /** 23 | * 下拉刷新View 24 | */ 25 | @property (nonatomic, strong) PDHeaderRefreshView *pdHeaderRefreshView; 26 | 27 | /** 28 | * 添加刷新 29 | * 30 | * @param actionHandler 回调 31 | */ 32 | - (void)pd_addHeaderRefreshWithNavigationBar:(BOOL)navBar 33 | andActionHandler:(ActionHandler)actionHandler; 34 | 35 | @end 36 | 37 | @interface PDHeaderRefreshView : UIView 38 | 39 | - (instancetype)initWithAssociatedScrollView:(UIScrollView *)scrollView 40 | withNavigationBar:(BOOL)navBar 41 | andRefreshViewHeight:(CGFloat)refreshViewHeight 42 | andActionHandler:(ActionHandler)actionHandler; 43 | /** 44 | * 停止刷新 45 | */ 46 | - (void)stopRefreshing; 47 | 48 | /** 49 | * 开始刷新 50 | */ 51 | - (void)startRefreshing; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /PDPullToRefresh/PDPullToRefresh/UIScrollView+PDHeaderRefreshView.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+PDHeaderRefreshView.m 3 | // PDPullToRefreshDemo 4 | // 5 | // Created by Panda on 16/1/15. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import "UIScrollView+PDHeaderRefreshView.h" 10 | #import 11 | #import 12 | #import 13 | 14 | static char UIScrollViewPDHeaderRefreshView; 15 | static char PDHeaderRefreshViewHeight; 16 | 17 | @implementation UIScrollView (PDHeaderRefreshView) 18 | 19 | - (void)setPdHeaderRefreshView:(PDHeaderRefreshView *)pdHeaderRefreshView { 20 | objc_setAssociatedObject(self, &UIScrollViewPDHeaderRefreshView, pdHeaderRefreshView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 21 | } 22 | 23 | - (PDHeaderRefreshView *)pdHeaderRefreshView { 24 | return objc_getAssociatedObject(self, &UIScrollViewPDHeaderRefreshView); 25 | } 26 | 27 | - (void)setPdHeaderRefreshViewHeight:(CGFloat)pdHeaderRefreshViewHeight { 28 | objc_setAssociatedObject(self, &PDHeaderRefreshViewHeight, @(MAX(0, pdHeaderRefreshViewHeight)), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 29 | } 30 | 31 | - (CGFloat)pdHeaderRefreshViewHeight { 32 | #if CGFLOAT_IS_DOUBLE 33 | return [objc_getAssociatedObject(self, &PDHeaderRefreshViewHeight) doubleValue]; 34 | #else 35 | return [objc_getAssociatedObject(self, &PDHeaderRefreshViewHeight) floatValue]; 36 | #endif 37 | } 38 | 39 | - (void)pd_addHeaderRefreshWithNavigationBar:(BOOL)navBar 40 | andActionHandler:(ActionHandler)actionHandler { 41 | if (!self.pdHeaderRefreshViewHeight) { 42 | self.pdHeaderRefreshViewHeight = 80; 43 | } 44 | 45 | self.pdHeaderRefreshView = [[PDHeaderRefreshView alloc]initWithAssociatedScrollView:self 46 | withNavigationBar:navBar 47 | andRefreshViewHeight:self.pdHeaderRefreshViewHeight 48 | andActionHandler:actionHandler]; 49 | 50 | [self insertSubview:self.pdHeaderRefreshView atIndex:0]; 51 | } 52 | 53 | @end 54 | 55 | @interface PDHeaderRefreshView () 56 | 57 | @property (nonatomic, retain) CALayer *animationLayer; 58 | @property (nonatomic, retain) CAShapeLayer *pathLayer; 59 | @property (nonatomic, weak)UIScrollView *associatedScrollView; 60 | @property (nonatomic, assign)CGFloat progress; 61 | @property (nonatomic, copy) ActionHandler handleBlock; 62 | @property (nonatomic, assign) BOOL isFlash; 63 | @property (nonatomic, strong) CAGradientLayer *gradientLayer; 64 | @property (nonatomic, copy) NSString *animationPacing; 65 | 66 | @end 67 | 68 | /** 默认光晕循环一次的持续时间 */ 69 | static const NSTimeInterval pHaloDuration = 1.5f; 70 | 71 | /** 默认光晕宽度 */ 72 | static const CGFloat pHaloWidth = 2.5f; 73 | 74 | /** 默认字体大小 */ 75 | static const double pFontSize = 26.0f; 76 | 77 | #define pColor [[UIColor colorWithRed:234.0/255 green:84.0/255 blue:87.0/255 alpha:1] CGColor] 78 | 79 | /** 光晕动画ID */ 80 | static NSString *const kAnimationKey = @"PDHeaderRefreshViewAnimationKey"; 81 | 82 | @implementation PDHeaderRefreshView { 83 | CGFloat originOffset; 84 | CGFloat PDPullToRefreshViewHeight; 85 | BOOL isStop; 86 | } 87 | 88 | - (instancetype)initWithAssociatedScrollView:(UIScrollView *)scrollView 89 | withNavigationBar:(BOOL)navBar 90 | andRefreshViewHeight:(CGFloat)refreshViewHeight 91 | andActionHandler:(ActionHandler)actionHandler { 92 | self = [super initWithFrame:CGRectMake(0, -refreshViewHeight, scrollView.bounds.size.width, refreshViewHeight)]; 93 | if (self) { 94 | if (navBar) { 95 | originOffset = 64.0f; 96 | }else{ 97 | originOffset = 0.0f; 98 | } 99 | 100 | self.associatedScrollView = scrollView; 101 | self.handleBlock = actionHandler; 102 | PDPullToRefreshViewHeight = refreshViewHeight; 103 | 104 | [self.associatedScrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; 105 | 106 | self.animationLayer = [CALayer layer]; 107 | self.animationLayer.frame = CGRectMake(0.0f, 0.0f, 108 | scrollView.bounds.size.width, 109 | refreshViewHeight); 110 | [self.layer addSublayer:self.animationLayer]; 111 | 112 | [self addPullAnimation]; 113 | isStop = YES; 114 | } 115 | return self; 116 | } 117 | 118 | - (void)setProgress:(CGFloat)progress { 119 | self.center = CGPointMake(self.center.x, -fabs(self.associatedScrollView.contentOffset.y+originOffset)/2); 120 | CGFloat diff = fabs(self.associatedScrollView.contentOffset.y + originOffset) - PDPullToRefreshViewHeight ; 121 | self.pathLayer.strokeEnd = progress; 122 | 123 | if (diff > 0) { 124 | if (!self.associatedScrollView.tracking) { 125 | if (!isStop) { 126 | return; 127 | } 128 | if (self.isFlash) { 129 | [self addRefreshAnimation]; 130 | [UIView animateWithDuration:0.3 animations:^{ 131 | 132 | self.associatedScrollView.contentInset = UIEdgeInsetsMake(PDPullToRefreshViewHeight + originOffset, 0, 0, 0); 133 | 134 | } completion:^(BOOL finished) { 135 | self.handleBlock(); 136 | }]; 137 | self.isFlash = NO; 138 | } 139 | 140 | } 141 | } 142 | } 143 | 144 | -(void)startRefreshing { 145 | [self addRefreshAnimation]; 146 | isStop = NO; 147 | [UIView animateWithDuration:0.3 animations:^{ 148 | self.associatedScrollView.contentInset = UIEdgeInsetsMake(PDPullToRefreshViewHeight + originOffset, 0, 0, 0); 149 | } completion:^(BOOL finished) { 150 | self.handleBlock(); 151 | isStop = YES; 152 | }]; 153 | } 154 | 155 | - (void)stopRefreshing { 156 | [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 157 | self.alpha = 0.0f; 158 | self.associatedScrollView.contentInset = UIEdgeInsetsMake(originOffset+0.1, 0, 0, 0); 159 | } completion:^(BOOL finished) { 160 | self.alpha = 1.0f; 161 | [self stopAnimating]; 162 | [self addPullAnimation]; 163 | self.pathLayer.strokeEnd = 0.0; 164 | }]; 165 | } 166 | 167 | #pragma mark - Animation Method 168 | 169 | - (CAShapeLayer *)setupDefaultLayer:(NSString *)animationString { 170 | if (self.pathLayer != nil) { 171 | [self.pathLayer removeFromSuperlayer]; 172 | self.pathLayer = nil; 173 | } 174 | 175 | CGMutablePathRef letters = CGPathCreateMutable(); 176 | 177 | CTFontRef font = CTFontCreateWithName(CFSTR("HelveticaNeue-UltraLight"), pFontSize, NULL); 178 | NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: 179 | (__bridge id)font, kCTFontAttributeName, 180 | nil]; 181 | NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:animationString 182 | attributes:attrs]; 183 | CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString); 184 | CFArrayRef runArray = CTLineGetGlyphRuns(line); 185 | 186 | // for each RUN 187 | for (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++) 188 | { 189 | // Get FONT for this run 190 | CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex); 191 | CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName); 192 | 193 | // for each GLYPH in run 194 | for (CFIndex runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++) 195 | { 196 | // get Glyph & Glyph-data 197 | CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1); 198 | CGGlyph glyph; 199 | CGPoint position; 200 | CTRunGetGlyphs(run, thisGlyphRange, &glyph); 201 | CTRunGetPositions(run, thisGlyphRange, &position); 202 | 203 | // Get PATH of outline 204 | { 205 | CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL); 206 | CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y); 207 | // CGAffineTransform t = CGAffineTransformIdentity; 208 | CGPathAddPath(letters, &t, letter); 209 | CGPathRelease(letter); 210 | } 211 | } 212 | } 213 | CFRelease(line); 214 | 215 | UIBezierPath *path = [UIBezierPath bezierPath]; 216 | [path moveToPoint:CGPointZero]; 217 | [path appendPath:[UIBezierPath bezierPathWithCGPath:letters]]; 218 | 219 | CGPathRelease(letters); 220 | CFRelease(font); 221 | 222 | CAShapeLayer *pathLayer = [CAShapeLayer layer]; 223 | pathLayer.frame = self.animationLayer.bounds; 224 | pathLayer.bounds = CGPathGetBoundingBox(path.CGPath); 225 | pathLayer.geometryFlipped = YES; 226 | pathLayer.path = path.CGPath; 227 | pathLayer.strokeColor = [UIColor colorWithRed:234.0/255 green:84.0/255 blue:87.0/255 alpha:1].CGColor; 228 | pathLayer.fillColor = nil; 229 | pathLayer.lineWidth = 1.0f; 230 | pathLayer.lineJoin = kCALineJoinBevel; 231 | 232 | return pathLayer; 233 | } 234 | 235 | - (void)addPullAnimation { 236 | // 这就是生活 237 | CAShapeLayer *pathLayer = [self setupDefaultLayer:@"C'est La Vie"]; 238 | [self.animationLayer addSublayer:pathLayer]; 239 | self.pathLayer = pathLayer; 240 | self.isFlash = YES; 241 | } 242 | 243 | - (void)addRefreshAnimation { 244 | _animationPacing = kCAMediaTimingFunctionEaseIn; 245 | 246 | // 设置渐变层参数 247 | CAGradientLayer *gradientLayer = [CAGradientLayer layer]; 248 | gradientLayer.frame = self.animationLayer.bounds; 249 | gradientLayer.startPoint = CGPointMake(- pHaloWidth, 0); 250 | gradientLayer.endPoint = CGPointMake(0, 0); 251 | gradientLayer.colors = @[(id)pColor, 252 | (id)[[UIColor whiteColor] CGColor], 253 | (id)pColor]; 254 | 255 | [self.animationLayer addSublayer:gradientLayer]; 256 | self.gradientLayer = gradientLayer; 257 | 258 | // 生活是美好的 259 | CAShapeLayer *pathLayer = [self setupDefaultLayer:@"La Vie est belle"]; 260 | self.gradientLayer.mask = pathLayer; 261 | 262 | if (self.pathLayer != nil) { 263 | [self.pathLayer removeFromSuperlayer]; 264 | self.pathLayer = nil; 265 | } 266 | [self startAnimating]; 267 | } 268 | 269 | /** 开启动画 */ 270 | - (void)startAnimating { 271 | static NSString *gradientStartPointKey = @"startPoint"; 272 | static NSString *gradientEndPointKey = @"endPoint"; 273 | 274 | CAGradientLayer *gradientLayer = (CAGradientLayer *)self.gradientLayer; 275 | if([gradientLayer animationForKey:kAnimationKey] == nil) 276 | { 277 | // 通过不断改变渐变的起止范围,来实现光晕效果 278 | CABasicAnimation *startPointAnimation = [CABasicAnimation animationWithKeyPath:gradientStartPointKey]; 279 | startPointAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(1.0, 0)]; 280 | startPointAnimation.timingFunction = [CAMediaTimingFunction functionWithName:_animationPacing]; 281 | 282 | CABasicAnimation *endPointAnimation = [CABasicAnimation animationWithKeyPath:gradientEndPointKey]; 283 | endPointAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(1 + pHaloWidth, 0)]; 284 | endPointAnimation.timingFunction = [CAMediaTimingFunction functionWithName:_animationPacing]; 285 | 286 | CAAnimationGroup *group = [CAAnimationGroup animation]; 287 | group.animations = @[startPointAnimation, endPointAnimation]; 288 | group.duration = pHaloDuration; 289 | group.timingFunction = [CAMediaTimingFunction functionWithName:_animationPacing]; 290 | group.repeatCount = HUGE_VALF; 291 | 292 | [gradientLayer addAnimation:group forKey:kAnimationKey]; 293 | } 294 | } 295 | 296 | /** 结束动画 */ 297 | - (void)stopAnimating { 298 | [self.gradientLayer removeFromSuperlayer]; 299 | self.gradientLayer = nil; 300 | } 301 | 302 | #pragma mark -- KVO 303 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 304 | change:(NSDictionary *)change 305 | context:(void *)context { 306 | if ([keyPath isEqualToString:@"contentOffset"]) { 307 | CGPoint contentOffset = [[change objectForKey:NSKeyValueChangeNewKey]CGPointValue]; 308 | if (contentOffset.y + originOffset <= 0) { 309 | self.progress = MAX(0.0, MIN(fabs(contentOffset.y+originOffset)/PDPullToRefreshViewHeight, 1.0)); 310 | } 311 | } 312 | } 313 | 314 | #pragma mark dealloc 315 | -(void)dealloc{ 316 | [self.associatedScrollView removeObserver:self forKeyPath:@"contentOffset"]; 317 | } 318 | 319 | @end 320 | 321 | -------------------------------------------------------------------------------- /PDPullToRefresh/Supporting Files/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 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /PDPullToRefresh/Supporting Files/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 | -------------------------------------------------------------------------------- /PDPullToRefresh/Supporting Files/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 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /PDPullToRefresh/Supporting Files/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 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /PDPullToRefresh/Supporting Files/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // PDPullToRefresh 4 | // 5 | // Created by Panda on 16/1/17. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /PDPullToRefreshTests/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /PDPullToRefreshTests/PDPullToRefreshTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // PDPullToRefreshTests.m 3 | // PDPullToRefreshTests 4 | // 5 | // Created by Panda on 16/1/17. 6 | // Copyright © 2016年 v2panda. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface PDPullToRefreshTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation PDPullToRefreshTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PDPullToRefresh 2 | 3 | * An easy way to use pull-to-refresh 4 | 5 | ![Gif](http://7xnmlk.com1.z0.glb.clouddn.com/PDPullToRefresh.gif) 6 | 7 | ## Installation 8 | 9 | ### From CocoaPods 10 | 11 | Add `pod 'PDPullToRefresh'` to your Podfile or `pod 'PDPullToRefresh', :head `if you're feeling adventurous. 12 | 13 | ### Manually 14 | 15 | _**Important note if your project doesn't use ARC**: you must add the `-fobjc-arc` compiler flag to `UIScrollView+PDHeaderRefreshView.m` and `UIScrollView+PDFooterRefreshView.m` in Target Settings > Build Phases > Compile Sources._ 16 | 17 | Drag the PDPullToRefresh/PDPullToRefresh folder into your project. 18 | Import PDPullToRefresh.h 19 | 20 | ## Usage 21 | 22 | (see sample Xcode project in `/PDPullToRefresh`) 23 | 24 | ### Adding Pull to Refresh 25 | 26 | ```objective-c 27 | [tableView pd_addHeaderRefreshWithNavigationBar:YES andActionHandler:^{ 28 | // prepend data to dataSource, insert cells at top of table view 29 | // call [tableView.pdHeaderRefreshView stopRefreshing] when done 30 | }]; 31 | ``` 32 | or if you want pull to refresh from the bottom 33 | 34 | ```objective-c 35 | [tableView pd_addFooterRefreshWithNavigationBar:YES andActionHandler:^{ 36 | // prepend data to dataSource, insert cells at top of table view 37 | // call [tableView.pdFooterRefreshView stopRefreshing] when done 38 | }]; 39 | ``` 40 | 41 | If you’d like to programmatically trigger the refresh (for instance in `viewDidAppear:`), you can do so with: 42 | 43 | ```objective-c 44 | [tableView.pdHeaderRefreshView startRefreshing]; 45 | ``` 46 | 47 | #### Customization 48 | 49 | The pull to refresh view can be customized using the following properties/methods: 50 | 51 | ```objective-c 52 | @property (nonatomic, assign) CGFloat pdHeaderRefreshViewHeight; 53 | @property (nonatomic, assign) CGFloat pdFooterRefreshViewHeight; 54 | ``` 55 | 56 | For instance, you would set the `pdHeaderRefreshViewHeight ` property using: 57 | 58 | ```objective-c 59 | // Default is 80 60 | tableView.pdHeaderRefreshViewHeight = 100; 61 | ``` 62 | 63 | 64 | ## Special Thanks 65 | 66 | PDPullToRefresh is Inspired by [半糖App](https://itunes.apple.com/cn/app/ban-tang/id955357564?mt=8)、[SVPullToRefresh](https://github.com/samvermette/SVPullToRefresh) 67 | 68 | 69 | 70 | ## License 71 | PDPullToRefresh is available under the MIT license. See the LICENSE file for more info. 72 | 73 | 74 | 75 | --------------------------------------------------------------------------------