├── .gitignore ├── LICENSE ├── README.md └── pullDownToExplode ├── 111222.gif ├── CLPullDownToExplodeView.swift ├── pullDownToExplode.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── pullDownToExplode ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift └── pullDownToExplodeTests ├── Info.plist └── pullDownToExplodeTests.swift /.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 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 iOS-mamu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pull_to_refresh 2 | pull to refresh with UIDynamic 3 | 4 | ![](https://raw.githubusercontent.com/iOS-mamu/pull_to_refresh/master/pullDownToExplode/111222.gif) 5 | 6 | a pull to refresh animation with UIDynamics 用UIDynamics做的下拉刷新动画 7 | 8 | codes are kinda messy now,but I will reconstruct them later.However,you can still download and copy the codes to integrate them into your project. 9 | 10 | 代码现在有点乱 以后会重构 但是 可以直接复制代码到你的项目来运行 11 | 12 | please feel free to modify 请自由修改 13 | 14 | -------------------------------------------------------------------------------- /pullDownToExplode/111222.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tickboxs/pull_to_refresh/5b9458da394db7edd8578c655670e7ba5ac74c34/pullDownToExplode/111222.gif -------------------------------------------------------------------------------- /pullDownToExplode/CLPullDownToExplodeView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CLPullDownToExplodeView.swift 3 | // pullDownToExplode 4 | // 5 | // Created by 蔡磊 on 16/6/12. 6 | // Copyright © 2016年 cailei. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | let appWidth = UIScreen.mainScreen().bounds.width 12 | let appHeight = UIScreen.mainScreen().bounds.height 13 | 14 | class CLPullDownToExplodeView: UIView { 15 | 16 | //MARK:property 17 | 18 | //count of items 19 | var numberOfItem:Int = 15 20 | 21 | var isAnimating = false 22 | 23 | //MARK:lazy loading 24 | lazy var animator:UIDynamicAnimator = UIDynamicAnimator(referenceView: self) 25 | 26 | var progressView = UIView() 27 | 28 | var progress:CGFloat { 29 | 30 | set(newValue) { 31 | 32 | if self.isAnimating == false{ 33 | progressView.transform = CGAffineTransformMakeScale(newValue, newValue) 34 | progressView.alpha = newValue 35 | progressView.layer.cornerRadius = 50*newValue*0.5 36 | } 37 | 38 | } 39 | get{ 40 | return 1 41 | } 42 | } 43 | 44 | 45 | //MARK:init 46 | init(){ 47 | super.init(frame: CGRectZero) 48 | prepareView() 49 | setupUI() 50 | } 51 | 52 | required init?(coder aDecoder: NSCoder) { 53 | fatalError("init(coder:) has not been implemented") 54 | } 55 | 56 | //MARK:UI 57 | private func prepareView() -> Void{ 58 | self.backgroundColor = UIColor.whiteColor() 59 | 60 | self.bounds = CGRect(x: 0, y: 0, width: appWidth, height: 300) 61 | } 62 | 63 | private func setupUI() -> Void{ 64 | 65 | //progressView 66 | addSubview(progressView) 67 | 68 | progressView.center = CGPoint(x: appWidth*0.5, y: 250) 69 | progressView.backgroundColor = UIColor.redColor() 70 | progressView.bounds = CGRect(x: 0, y: 0, width: 50, height: 50) 71 | progressView.clipsToBounds = true 72 | progressView.alpha = 0 73 | 74 | } 75 | 76 | //MARK: explosion animation 77 | func explosion() -> Void{ 78 | 79 | //小球乱跳动画 80 | let itemBehavior = UIDynamicItemBehavior() 81 | let gravity = UIGravityBehavior() 82 | let collision = UICollisionBehavior() 83 | 84 | for _ in 0...numberOfItem{ 85 | 86 | //randomize the startColor and endColor 87 | let startColor = UIColor(red: CGFloat(arc4random_uniform(256))/256, green: CGFloat(arc4random_uniform(256))/256, blue: CGFloat(arc4random_uniform(256))/256, alpha: 1).CGColor 88 | let endColor = UIColor(red: CGFloat(arc4random_uniform(256))/256, green: CGFloat(arc4random_uniform(256))/256, blue: CGFloat(arc4random_uniform(256))/256, alpha: 1).CGColor 89 | 90 | let itemView = CLPullDownToExplodeViewItem(StartColor: startColor, EndColor: endColor) 91 | 92 | self.addSubview(itemView) 93 | let xOffset = Int(arc4random_uniform(200)) 94 | let yOffset = Int(arc4random_uniform(200)) 95 | itemView.frame = CGRect(x: 50+xOffset, y: 50+yOffset, width: 20, height: 20) 96 | itemBehavior.addItem(itemView) 97 | 98 | let velocityOffsetX = CGFloat(arc4random_uniform(100)) 99 | let velocityOffsetY = CGFloat(arc4random_uniform(100)) 100 | 101 | itemBehavior.addLinearVelocity(CGPointMake(-50+velocityOffsetX, -50+velocityOffsetY), forItem: itemView) 102 | 103 | let angularVelocityOffset = CGFloat(arc4random_uniform(UInt32(M_PI*2))) 104 | itemBehavior.addAngularVelocity(CGFloat(CGFloat(-M_PI)+angularVelocityOffset), forItem: itemView) 105 | gravity.addItem(itemView) 106 | collision.addItem(itemView) 107 | } 108 | 109 | //MARK:设置物理引擎 110 | itemBehavior.allowsRotation = true 111 | itemBehavior.elasticity = 0.9 112 | itemBehavior.friction = 0 113 | itemBehavior.density = 0.5 114 | itemBehavior.resistance = 0.05 115 | itemBehavior.angularResistance = 0.05 116 | 117 | 118 | // magnitude越大,速度增长越快 119 | gravity.magnitude = 0.5 120 | // 添加元素 告诉仿真器哪些元素添加重力行为,创建碰撞行为 121 | // 设置碰撞的边界 122 | collision.translatesReferenceBoundsIntoBoundary = true 123 | 124 | // 3.开始仿真 125 | // 添加到仿真器中开始仿真 126 | animator.addBehavior(gravity) 127 | animator.addBehavior(collision) 128 | animator.addBehavior(itemBehavior) 129 | 130 | //progressView小球爆炸动画 131 | UIView.animateWithDuration(0.25, animations: { 132 | self.progressView.alpha = 0 133 | self.progressView.transform = CGAffineTransformMakeScale(0, 0) 134 | }) { (stop) in 135 | self.progressView.transform = CGAffineTransformIdentity 136 | } 137 | 138 | self.isAnimating = true 139 | 140 | } 141 | 142 | //结束爆炸动画 143 | func endExplosion() -> Void{ 144 | 145 | animator.removeAllBehaviors() 146 | for subView in self.subviews{ 147 | UIView.animateWithDuration(0.25, animations: { 148 | 149 | if (subView as UIView) != self.progressView{ 150 | (subView as UIView).alpha = 0 151 | (subView as UIView).bounds = CGRectZero 152 | } 153 | 154 | }, completion: { (stop) in 155 | if (subView as UIView) != self.progressView{ 156 | (subView as UIView).removeFromSuperview() 157 | } 158 | }) 159 | 160 | } 161 | 162 | } 163 | 164 | 165 | } 166 | 167 | class CLPullDownToExplodeViewItem: UIView { 168 | 169 | 170 | override var collisionBoundsType: UIDynamicItemCollisionBoundsType { 171 | return .Ellipse 172 | } 173 | 174 | //MARK:property 175 | var startColor:CGColor? 176 | var endColor:CGColor? 177 | 178 | //MARK:init 179 | init(){ 180 | super.init(frame: CGRectZero) 181 | prepareView() 182 | setupUI() 183 | } 184 | 185 | init(StartColor startColor:CGColor,EndColor endColor:CGColor){ 186 | super.init(frame: CGRectZero) 187 | self.startColor = startColor 188 | self.endColor = endColor 189 | 190 | prepareView() 191 | setupUI() 192 | 193 | } 194 | 195 | required init?(coder aDecoder: NSCoder) { 196 | fatalError("init(coder:) has not been implemented") 197 | } 198 | 199 | //MARK:UI 200 | private func prepareView() -> Void{ 201 | 202 | self.backgroundColor = UIColor.lightGrayColor() 203 | self.bounds = CGRect(x: 0, y: 0, width: 20, height: 20) 204 | self.layer.borderColor = UIColor.blackColor().CGColor 205 | self.layer.cornerRadius = 10 206 | self.clipsToBounds = true 207 | } 208 | 209 | private func setupUI() -> Void{ 210 | 211 | //add gradient layer 212 | let gradientLayer = CAGradientLayer() 213 | gradientLayer.frame = CGRect(x: -20, y: 0, width: 60, height: 20) 214 | gradientLayer.startPoint = CGPointMake(0, 0) 215 | gradientLayer.endPoint = CGPointMake(1, 1) 216 | gradientLayer.locations = [0.0,1.0] 217 | gradientLayer.colors = [startColor!,endColor!] 218 | self.layer.addSublayer(gradientLayer) 219 | 220 | } 221 | } 222 | 223 | 224 | -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplode.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F7C3076E1D0D42C30044177C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C3076D1D0D42C30044177C /* AppDelegate.swift */; }; 11 | F7C307701D0D42C30044177C /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C3076F1D0D42C30044177C /* ViewController.swift */; }; 12 | F7C307731D0D42C30044177C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7C307711D0D42C30044177C /* Main.storyboard */; }; 13 | F7C307751D0D42C30044177C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F7C307741D0D42C30044177C /* Assets.xcassets */; }; 14 | F7C307781D0D42C30044177C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7C307761D0D42C30044177C /* LaunchScreen.storyboard */; }; 15 | F7C307831D0D42C40044177C /* pullDownToExplodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C307821D0D42C40044177C /* pullDownToExplodeTests.swift */; }; 16 | F7C3078E1D0D447C0044177C /* CLPullDownToExplodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C3078D1D0D447C0044177C /* CLPullDownToExplodeView.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | F7C3077F1D0D42C40044177C /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = F7C307621D0D42C30044177C /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = F7C307691D0D42C30044177C; 25 | remoteInfo = pullDownToExplode; 26 | }; 27 | /* End PBXContainerItemProxy section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | F7C3076A1D0D42C30044177C /* pullDownToExplode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = pullDownToExplode.app; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | F7C3076D1D0D42C30044177C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 32 | F7C3076F1D0D42C30044177C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 33 | F7C307721D0D42C30044177C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 34 | F7C307741D0D42C30044177C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 35 | F7C307771D0D42C30044177C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 36 | F7C307791D0D42C30044177C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | F7C3077E1D0D42C40044177C /* pullDownToExplodeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = pullDownToExplodeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | F7C307821D0D42C40044177C /* pullDownToExplodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = pullDownToExplodeTests.swift; sourceTree = ""; }; 39 | F7C307841D0D42C40044177C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 40 | F7C3078D1D0D447C0044177C /* CLPullDownToExplodeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CLPullDownToExplodeView.swift; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | F7C307671D0D42C30044177C /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | F7C3077B1D0D42C40044177C /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | /* End PBXFrameworksBuildPhase section */ 59 | 60 | /* Begin PBXGroup section */ 61 | F7C307611D0D42C30044177C = { 62 | isa = PBXGroup; 63 | children = ( 64 | F7C3078D1D0D447C0044177C /* CLPullDownToExplodeView.swift */, 65 | F7C3076C1D0D42C30044177C /* pullDownToExplode */, 66 | F7C307811D0D42C40044177C /* pullDownToExplodeTests */, 67 | F7C3076B1D0D42C30044177C /* Products */, 68 | ); 69 | sourceTree = ""; 70 | }; 71 | F7C3076B1D0D42C30044177C /* Products */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | F7C3076A1D0D42C30044177C /* pullDownToExplode.app */, 75 | F7C3077E1D0D42C40044177C /* pullDownToExplodeTests.xctest */, 76 | ); 77 | name = Products; 78 | sourceTree = ""; 79 | }; 80 | F7C3076C1D0D42C30044177C /* pullDownToExplode */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | F7C3076D1D0D42C30044177C /* AppDelegate.swift */, 84 | F7C3076F1D0D42C30044177C /* ViewController.swift */, 85 | F7C307711D0D42C30044177C /* Main.storyboard */, 86 | F7C307741D0D42C30044177C /* Assets.xcassets */, 87 | F7C307761D0D42C30044177C /* LaunchScreen.storyboard */, 88 | F7C307791D0D42C30044177C /* Info.plist */, 89 | ); 90 | path = pullDownToExplode; 91 | sourceTree = ""; 92 | }; 93 | F7C307811D0D42C40044177C /* pullDownToExplodeTests */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | F7C307821D0D42C40044177C /* pullDownToExplodeTests.swift */, 97 | F7C307841D0D42C40044177C /* Info.plist */, 98 | ); 99 | path = pullDownToExplodeTests; 100 | sourceTree = ""; 101 | }; 102 | /* End PBXGroup section */ 103 | 104 | /* Begin PBXNativeTarget section */ 105 | F7C307691D0D42C30044177C /* pullDownToExplode */ = { 106 | isa = PBXNativeTarget; 107 | buildConfigurationList = F7C307871D0D42C40044177C /* Build configuration list for PBXNativeTarget "pullDownToExplode" */; 108 | buildPhases = ( 109 | F7C307661D0D42C30044177C /* Sources */, 110 | F7C307671D0D42C30044177C /* Frameworks */, 111 | F7C307681D0D42C30044177C /* Resources */, 112 | ); 113 | buildRules = ( 114 | ); 115 | dependencies = ( 116 | ); 117 | name = pullDownToExplode; 118 | productName = pullDownToExplode; 119 | productReference = F7C3076A1D0D42C30044177C /* pullDownToExplode.app */; 120 | productType = "com.apple.product-type.application"; 121 | }; 122 | F7C3077D1D0D42C40044177C /* pullDownToExplodeTests */ = { 123 | isa = PBXNativeTarget; 124 | buildConfigurationList = F7C3078A1D0D42C40044177C /* Build configuration list for PBXNativeTarget "pullDownToExplodeTests" */; 125 | buildPhases = ( 126 | F7C3077A1D0D42C40044177C /* Sources */, 127 | F7C3077B1D0D42C40044177C /* Frameworks */, 128 | F7C3077C1D0D42C40044177C /* Resources */, 129 | ); 130 | buildRules = ( 131 | ); 132 | dependencies = ( 133 | F7C307801D0D42C40044177C /* PBXTargetDependency */, 134 | ); 135 | name = pullDownToExplodeTests; 136 | productName = pullDownToExplodeTests; 137 | productReference = F7C3077E1D0D42C40044177C /* pullDownToExplodeTests.xctest */; 138 | productType = "com.apple.product-type.bundle.unit-test"; 139 | }; 140 | /* End PBXNativeTarget section */ 141 | 142 | /* Begin PBXProject section */ 143 | F7C307621D0D42C30044177C /* Project object */ = { 144 | isa = PBXProject; 145 | attributes = { 146 | LastSwiftUpdateCheck = 0730; 147 | LastUpgradeCheck = 0730; 148 | ORGANIZATIONNAME = cailei; 149 | TargetAttributes = { 150 | F7C307691D0D42C30044177C = { 151 | CreatedOnToolsVersion = 7.3; 152 | }; 153 | F7C3077D1D0D42C40044177C = { 154 | CreatedOnToolsVersion = 7.3; 155 | TestTargetID = F7C307691D0D42C30044177C; 156 | }; 157 | }; 158 | }; 159 | buildConfigurationList = F7C307651D0D42C30044177C /* Build configuration list for PBXProject "pullDownToExplode" */; 160 | compatibilityVersion = "Xcode 3.2"; 161 | developmentRegion = English; 162 | hasScannedForEncodings = 0; 163 | knownRegions = ( 164 | en, 165 | Base, 166 | ); 167 | mainGroup = F7C307611D0D42C30044177C; 168 | productRefGroup = F7C3076B1D0D42C30044177C /* Products */; 169 | projectDirPath = ""; 170 | projectRoot = ""; 171 | targets = ( 172 | F7C307691D0D42C30044177C /* pullDownToExplode */, 173 | F7C3077D1D0D42C40044177C /* pullDownToExplodeTests */, 174 | ); 175 | }; 176 | /* End PBXProject section */ 177 | 178 | /* Begin PBXResourcesBuildPhase section */ 179 | F7C307681D0D42C30044177C /* Resources */ = { 180 | isa = PBXResourcesBuildPhase; 181 | buildActionMask = 2147483647; 182 | files = ( 183 | F7C307781D0D42C30044177C /* LaunchScreen.storyboard in Resources */, 184 | F7C307751D0D42C30044177C /* Assets.xcassets in Resources */, 185 | F7C307731D0D42C30044177C /* Main.storyboard in Resources */, 186 | ); 187 | runOnlyForDeploymentPostprocessing = 0; 188 | }; 189 | F7C3077C1D0D42C40044177C /* Resources */ = { 190 | isa = PBXResourcesBuildPhase; 191 | buildActionMask = 2147483647; 192 | files = ( 193 | ); 194 | runOnlyForDeploymentPostprocessing = 0; 195 | }; 196 | /* End PBXResourcesBuildPhase section */ 197 | 198 | /* Begin PBXSourcesBuildPhase section */ 199 | F7C307661D0D42C30044177C /* Sources */ = { 200 | isa = PBXSourcesBuildPhase; 201 | buildActionMask = 2147483647; 202 | files = ( 203 | F7C307701D0D42C30044177C /* ViewController.swift in Sources */, 204 | F7C3076E1D0D42C30044177C /* AppDelegate.swift in Sources */, 205 | F7C3078E1D0D447C0044177C /* CLPullDownToExplodeView.swift in Sources */, 206 | ); 207 | runOnlyForDeploymentPostprocessing = 0; 208 | }; 209 | F7C3077A1D0D42C40044177C /* Sources */ = { 210 | isa = PBXSourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | F7C307831D0D42C40044177C /* pullDownToExplodeTests.swift in Sources */, 214 | ); 215 | runOnlyForDeploymentPostprocessing = 0; 216 | }; 217 | /* End PBXSourcesBuildPhase section */ 218 | 219 | /* Begin PBXTargetDependency section */ 220 | F7C307801D0D42C40044177C /* PBXTargetDependency */ = { 221 | isa = PBXTargetDependency; 222 | target = F7C307691D0D42C30044177C /* pullDownToExplode */; 223 | targetProxy = F7C3077F1D0D42C40044177C /* PBXContainerItemProxy */; 224 | }; 225 | /* End PBXTargetDependency section */ 226 | 227 | /* Begin PBXVariantGroup section */ 228 | F7C307711D0D42C30044177C /* Main.storyboard */ = { 229 | isa = PBXVariantGroup; 230 | children = ( 231 | F7C307721D0D42C30044177C /* Base */, 232 | ); 233 | name = Main.storyboard; 234 | sourceTree = ""; 235 | }; 236 | F7C307761D0D42C30044177C /* LaunchScreen.storyboard */ = { 237 | isa = PBXVariantGroup; 238 | children = ( 239 | F7C307771D0D42C30044177C /* Base */, 240 | ); 241 | name = LaunchScreen.storyboard; 242 | sourceTree = ""; 243 | }; 244 | /* End PBXVariantGroup section */ 245 | 246 | /* Begin XCBuildConfiguration section */ 247 | F7C307851D0D42C40044177C /* Debug */ = { 248 | isa = XCBuildConfiguration; 249 | buildSettings = { 250 | ALWAYS_SEARCH_USER_PATHS = NO; 251 | CLANG_ANALYZER_NONNULL = YES; 252 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 253 | CLANG_CXX_LIBRARY = "libc++"; 254 | CLANG_ENABLE_MODULES = YES; 255 | CLANG_ENABLE_OBJC_ARC = YES; 256 | CLANG_WARN_BOOL_CONVERSION = YES; 257 | CLANG_WARN_CONSTANT_CONVERSION = YES; 258 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 259 | CLANG_WARN_EMPTY_BODY = YES; 260 | CLANG_WARN_ENUM_CONVERSION = YES; 261 | CLANG_WARN_INT_CONVERSION = YES; 262 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 263 | CLANG_WARN_UNREACHABLE_CODE = YES; 264 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 265 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 266 | COPY_PHASE_STRIP = NO; 267 | DEBUG_INFORMATION_FORMAT = dwarf; 268 | ENABLE_STRICT_OBJC_MSGSEND = YES; 269 | ENABLE_TESTABILITY = YES; 270 | GCC_C_LANGUAGE_STANDARD = gnu99; 271 | GCC_DYNAMIC_NO_PIC = NO; 272 | GCC_NO_COMMON_BLOCKS = YES; 273 | GCC_OPTIMIZATION_LEVEL = 0; 274 | GCC_PREPROCESSOR_DEFINITIONS = ( 275 | "DEBUG=1", 276 | "$(inherited)", 277 | ); 278 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 279 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 280 | GCC_WARN_UNDECLARED_SELECTOR = YES; 281 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 282 | GCC_WARN_UNUSED_FUNCTION = YES; 283 | GCC_WARN_UNUSED_VARIABLE = YES; 284 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 285 | MTL_ENABLE_DEBUG_INFO = YES; 286 | ONLY_ACTIVE_ARCH = YES; 287 | SDKROOT = iphoneos; 288 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 289 | }; 290 | name = Debug; 291 | }; 292 | F7C307861D0D42C40044177C /* Release */ = { 293 | isa = XCBuildConfiguration; 294 | buildSettings = { 295 | ALWAYS_SEARCH_USER_PATHS = NO; 296 | CLANG_ANALYZER_NONNULL = YES; 297 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 298 | CLANG_CXX_LIBRARY = "libc++"; 299 | CLANG_ENABLE_MODULES = YES; 300 | CLANG_ENABLE_OBJC_ARC = YES; 301 | CLANG_WARN_BOOL_CONVERSION = YES; 302 | CLANG_WARN_CONSTANT_CONVERSION = YES; 303 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 304 | CLANG_WARN_EMPTY_BODY = YES; 305 | CLANG_WARN_ENUM_CONVERSION = YES; 306 | CLANG_WARN_INT_CONVERSION = YES; 307 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 308 | CLANG_WARN_UNREACHABLE_CODE = YES; 309 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 310 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 311 | COPY_PHASE_STRIP = NO; 312 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 313 | ENABLE_NS_ASSERTIONS = NO; 314 | ENABLE_STRICT_OBJC_MSGSEND = YES; 315 | GCC_C_LANGUAGE_STANDARD = gnu99; 316 | GCC_NO_COMMON_BLOCKS = YES; 317 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 318 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 319 | GCC_WARN_UNDECLARED_SELECTOR = YES; 320 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 321 | GCC_WARN_UNUSED_FUNCTION = YES; 322 | GCC_WARN_UNUSED_VARIABLE = YES; 323 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 324 | MTL_ENABLE_DEBUG_INFO = NO; 325 | SDKROOT = iphoneos; 326 | VALIDATE_PRODUCT = YES; 327 | }; 328 | name = Release; 329 | }; 330 | F7C307881D0D42C40044177C /* Debug */ = { 331 | isa = XCBuildConfiguration; 332 | buildSettings = { 333 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 334 | INFOPLIST_FILE = pullDownToExplode/Info.plist; 335 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 336 | PRODUCT_BUNDLE_IDENTIFIER = cailei.pullDownToExplode; 337 | PRODUCT_NAME = "$(TARGET_NAME)"; 338 | }; 339 | name = Debug; 340 | }; 341 | F7C307891D0D42C40044177C /* Release */ = { 342 | isa = XCBuildConfiguration; 343 | buildSettings = { 344 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 345 | INFOPLIST_FILE = pullDownToExplode/Info.plist; 346 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 347 | PRODUCT_BUNDLE_IDENTIFIER = cailei.pullDownToExplode; 348 | PRODUCT_NAME = "$(TARGET_NAME)"; 349 | }; 350 | name = Release; 351 | }; 352 | F7C3078B1D0D42C40044177C /* Debug */ = { 353 | isa = XCBuildConfiguration; 354 | buildSettings = { 355 | BUNDLE_LOADER = "$(TEST_HOST)"; 356 | INFOPLIST_FILE = pullDownToExplodeTests/Info.plist; 357 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 358 | PRODUCT_BUNDLE_IDENTIFIER = cailei.pullDownToExplodeTests; 359 | PRODUCT_NAME = "$(TARGET_NAME)"; 360 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/pullDownToExplode.app/pullDownToExplode"; 361 | }; 362 | name = Debug; 363 | }; 364 | F7C3078C1D0D42C40044177C /* Release */ = { 365 | isa = XCBuildConfiguration; 366 | buildSettings = { 367 | BUNDLE_LOADER = "$(TEST_HOST)"; 368 | INFOPLIST_FILE = pullDownToExplodeTests/Info.plist; 369 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 370 | PRODUCT_BUNDLE_IDENTIFIER = cailei.pullDownToExplodeTests; 371 | PRODUCT_NAME = "$(TARGET_NAME)"; 372 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/pullDownToExplode.app/pullDownToExplode"; 373 | }; 374 | name = Release; 375 | }; 376 | /* End XCBuildConfiguration section */ 377 | 378 | /* Begin XCConfigurationList section */ 379 | F7C307651D0D42C30044177C /* Build configuration list for PBXProject "pullDownToExplode" */ = { 380 | isa = XCConfigurationList; 381 | buildConfigurations = ( 382 | F7C307851D0D42C40044177C /* Debug */, 383 | F7C307861D0D42C40044177C /* Release */, 384 | ); 385 | defaultConfigurationIsVisible = 0; 386 | defaultConfigurationName = Release; 387 | }; 388 | F7C307871D0D42C40044177C /* Build configuration list for PBXNativeTarget "pullDownToExplode" */ = { 389 | isa = XCConfigurationList; 390 | buildConfigurations = ( 391 | F7C307881D0D42C40044177C /* Debug */, 392 | F7C307891D0D42C40044177C /* Release */, 393 | ); 394 | defaultConfigurationIsVisible = 0; 395 | }; 396 | F7C3078A1D0D42C40044177C /* Build configuration list for PBXNativeTarget "pullDownToExplodeTests" */ = { 397 | isa = XCConfigurationList; 398 | buildConfigurations = ( 399 | F7C3078B1D0D42C40044177C /* Debug */, 400 | F7C3078C1D0D42C40044177C /* Release */, 401 | ); 402 | defaultConfigurationIsVisible = 0; 403 | }; 404 | /* End XCConfigurationList section */ 405 | }; 406 | rootObject = F7C307621D0D42C30044177C /* Project object */; 407 | } 408 | -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplode.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplode/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // pullDownToExplode 4 | // 5 | // Created by 蔡磊 on 16/6/12. 6 | // Copyright © 2016年 cailei. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplode/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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplode/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 | -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplode/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 | -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplode/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 | 40 | 41 | -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplode/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // pullDownToExplode 4 | // 5 | // Created by 蔡磊 on 16/6/12. 6 | // Copyright © 2016年 cailei. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate { 12 | 13 | lazy var refView = CLPullDownToExplodeView() 14 | 15 | lazy var tableView = UITableView(frame: CGRect(x: 0, y: 0, width: appWidth, height: appHeight), style: .Plain) 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | // Do any additional setup after loading the view, typically from a nib. 20 | 21 | prepareView() 22 | setupUI() 23 | 24 | } 25 | 26 | //MARK:UI 27 | private func prepareView() -> Void{ 28 | 29 | } 30 | 31 | private func setupUI() -> Void{ 32 | view.addSubview(tableView) 33 | tableView.addSubview(refView) 34 | refView.frame = CGRect(x: 0, y: -300, width: appWidth, height: 300) 35 | 36 | tableView.dataSource = self 37 | tableView.delegate = self 38 | 39 | } 40 | 41 | override func touchesBegan(touches: Set, withEvent event: UIEvent?) { 42 | refView.endExplosion() 43 | } 44 | 45 | //MARK:tableView dataSource 46 | func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 47 | return 100 48 | } 49 | 50 | func numberOfSectionsInTableView(tableView: UITableView) -> Int { 51 | return 1 52 | } 53 | 54 | func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 55 | return UITableViewCell() 56 | } 57 | 58 | func scrollViewDidScroll(scrollView: UIScrollView) { 59 | 60 | let progress = scrollView.contentOffset.y/100 61 | if (progress <= 0.0 && progress >= -1.0){ 62 | 63 | self.refView.progress = -progress 64 | 65 | //超过阈值则执行动画 66 | if( progress <= -0.9){ 67 | 68 | self.tableView.contentInset = UIEdgeInsets(top: 100, left: 0, bottom: 0, right: 0) 69 | //如果有动画进行 则直接返回 70 | if self.refView.subviews.count > 1{ 71 | return 72 | } 73 | self.refView.explosion() 74 | 75 | let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(3 * Double(NSEC_PER_SEC))) 76 | dispatch_after(delayTime, dispatch_get_main_queue()) { 77 | self.refView.endExplosion() 78 | scrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: true) 79 | let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.25 * Double(NSEC_PER_SEC))) 80 | dispatch_after(delayTime, dispatch_get_main_queue()) { 81 | scrollView.contentInset = UIEdgeInsetsZero 82 | self.refView.isAnimating = false 83 | 84 | 85 | } 86 | } 87 | 88 | } 89 | 90 | } 91 | } 92 | 93 | 94 | } 95 | 96 | -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplodeTests/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 | -------------------------------------------------------------------------------- /pullDownToExplode/pullDownToExplodeTests/pullDownToExplodeTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // pullDownToExplodeTests.swift 3 | // pullDownToExplodeTests 4 | // 5 | // Created by 蔡磊 on 16/6/12. 6 | // Copyright © 2016年 cailei. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import pullDownToExplode 11 | 12 | class pullDownToExplodeTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------