├── .gitignore ├── LICENSE ├── LxThroughPointsBezier.podspec ├── LxThroughPointsBezier ├── UIBezierPath+LxThroughPointsBezier.h └── UIBezierPath+LxThroughPointsBezier.m ├── LxThroughPointsBezierDemo ├── LxThroughPointsBezierDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── LxThroughPointsBezierDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard │ ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── LxThroughPointsBezierDemo.xcdatamodeld │ ├── .xccurrentversion │ └── LxThroughPointsBezierDemo.xcdatamodel │ │ └── contents │ ├── PointView.h │ ├── PointView.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── README.md └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /LxThroughPointsBezier.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'LxThroughPointsBezier' 3 | s.version = '1.0.0' 4 | s.license = 'Apache' 5 | s.summary = 'Draw a smooth bezier through several points you designated. The curve‘s bend level is adjustable.' 6 | s.homepage = 'https://github.com/DeveloperLx/LxThroughPointsBezier' 7 | s.authors = { 'DeveloperLx' => 'developerlx@yeah.net' } 8 | s.source = { :git => 'https://github.com/DeveloperLx/LxThroughPointsBezier.git', :tag => s.version, :submodules => true } 9 | s.requires_arc = true 10 | 11 | s.ios.deployment_target = '6.0' 12 | 13 | s.public_header_files = 'LxThroughPointsBezier/*.h' 14 | s.source_files = 'LxThroughPointsBezier/*' 15 | 16 | s.frameworks = 'Foundation', 'CoreGraphics' 17 | 18 | end 19 | -------------------------------------------------------------------------------- /LxThroughPointsBezier/UIBezierPath+LxThroughPointsBezier.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIBezierPath+LxThroughPointsBezier.h 3 | // LxThroughPointsBezierDemo 4 | // 5 | 6 | #import 7 | 8 | @interface UIBezierPath (LxThroughPointsBezier) 9 | 10 | /** 11 | * The curve‘s bend level. The good value is about 0.6 ~ 0.8. The default and recommended value is 0.7. 12 | */ 13 | @property (nonatomic) CGFloat contractionFactor; 14 | 15 | /** 16 | * You must wrap CGPoint struct to NSValue object. 17 | * 18 | * @param pointArray Points you want to through. You must give at least 1 point for drawing curve. 19 | */ 20 | - (void)addBezierThroughPoints:(NSArray *)pointArray; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /LxThroughPointsBezier/UIBezierPath+LxThroughPointsBezier.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIBezierPath+LxThroughPointsBezier.m 3 | // LxThroughPointsBezierDemo 4 | // 5 | 6 | #import "UIBezierPath+LxThroughPointsBezier.h" 7 | #import 8 | 9 | @implementation UIBezierPath (LxThroughPointsBezier) 10 | 11 | - (void)setContractionFactor:(CGFloat)contractionFactor 12 | { 13 | objc_setAssociatedObject(self, @selector(contractionFactor), @(contractionFactor), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 14 | } 15 | 16 | - (CGFloat)contractionFactor 17 | { 18 | id contractionFactorAssociatedObject = objc_getAssociatedObject(self, @selector(contractionFactor)); 19 | if (contractionFactorAssociatedObject == nil) { 20 | return 0.7; 21 | } 22 | return [contractionFactorAssociatedObject floatValue]; 23 | } 24 | 25 | - (void)addBezierThroughPoints:(NSArray *)pointArray 26 | { 27 | NSAssert(pointArray.count > 0, @"You must give at least 1 point for drawing the curve."); 28 | 29 | if (pointArray.count < 3) { 30 | switch (pointArray.count) { 31 | case 1: 32 | { 33 | NSValue * point0Value = pointArray[0]; 34 | CGPoint point0 = [point0Value CGPointValue]; 35 | [self addLineToPoint:point0]; 36 | } 37 | break; 38 | case 2: 39 | { 40 | NSValue * point0Value = pointArray[0]; 41 | CGPoint point0 = [point0Value CGPointValue]; 42 | NSValue * point1Value = pointArray[1]; 43 | CGPoint point1 = [point1Value CGPointValue]; 44 | [self addQuadCurveToPoint:point1 controlPoint:ControlPointForTheBezierCanThrough3Point(self.currentPoint, point0, point1)]; 45 | } 46 | break; 47 | default: 48 | break; 49 | } 50 | } 51 | 52 | CGPoint previousPoint = CGPointZero; 53 | 54 | CGPoint previousCenterPoint = CGPointZero; 55 | CGPoint centerPoint = CGPointZero; 56 | CGFloat centerPointDistance = 0; 57 | 58 | CGFloat obliqueAngle = 0; 59 | 60 | CGPoint previousControlPoint1 = CGPointZero; 61 | CGPoint previousControlPoint2 = CGPointZero; 62 | CGPoint controlPoint1 = CGPointZero; 63 | 64 | previousPoint = self.currentPoint; 65 | 66 | for (int i = 0; i < pointArray.count; i++) { 67 | 68 | NSValue * pointIValue = pointArray[i]; 69 | CGPoint pointI = [pointIValue CGPointValue]; 70 | 71 | if (i > 0) { 72 | 73 | previousCenterPoint = CenterPointOf(self.currentPoint, previousPoint); 74 | centerPoint = CenterPointOf(previousPoint, pointI); 75 | 76 | centerPointDistance = DistanceBetweenPoint(previousCenterPoint, centerPoint); 77 | 78 | obliqueAngle = ObliqueAngleOfStraightThrough(centerPoint, previousCenterPoint); 79 | 80 | previousControlPoint2 = CGPointMake(previousPoint.x - 0.5 * self.contractionFactor * centerPointDistance * cos(obliqueAngle), previousPoint.y - 0.5 * self.contractionFactor * centerPointDistance * sin(obliqueAngle)); 81 | controlPoint1 = CGPointMake(previousPoint.x + 0.5 * self.contractionFactor * centerPointDistance * cos(obliqueAngle), previousPoint.y + 0.5 * self.contractionFactor * centerPointDistance * sin(obliqueAngle)); 82 | } 83 | 84 | if (i == 1) { 85 | 86 | [self addQuadCurveToPoint:previousPoint controlPoint:previousControlPoint2]; 87 | } 88 | else if (i > 1 && i < pointArray.count - 1) { 89 | 90 | [self addCurveToPoint:previousPoint controlPoint1:previousControlPoint1 controlPoint2:previousControlPoint2]; 91 | } 92 | else if (i == pointArray.count - 1) { 93 | 94 | [self addCurveToPoint:previousPoint controlPoint1:previousControlPoint1 controlPoint2:previousControlPoint2]; 95 | [self addQuadCurveToPoint:pointI controlPoint:controlPoint1]; 96 | } 97 | else { 98 | 99 | } 100 | 101 | previousControlPoint1 = controlPoint1; 102 | previousPoint = pointI; 103 | } 104 | } 105 | 106 | CGFloat ObliqueAngleOfStraightThrough(CGPoint point1, CGPoint point2) // [-π/2, 3π/2) 107 | { 108 | CGFloat obliqueRatio = 0; 109 | CGFloat obliqueAngle = 0; 110 | 111 | if (point1.x > point2.x) { 112 | 113 | obliqueRatio = (point2.y - point1.y) / (point2.x - point1.x); 114 | obliqueAngle = atan(obliqueRatio); 115 | } 116 | else if (point1.x < point2.x) { 117 | 118 | obliqueRatio = (point2.y - point1.y) / (point2.x - point1.x); 119 | obliqueAngle = M_PI + atan(obliqueRatio); 120 | } 121 | else if (point2.y - point1.y >= 0) { 122 | 123 | obliqueAngle = M_PI/2; 124 | } 125 | else { 126 | obliqueAngle = -M_PI/2; 127 | } 128 | 129 | return obliqueAngle; 130 | } 131 | 132 | CGPoint ControlPointForTheBezierCanThrough3Point(CGPoint point1, CGPoint point2, CGPoint point3) 133 | { 134 | return CGPointMake(2 * point2.x - (point1.x + point3.x) / 2, 2 * point2.y - (point1.y + point3.y) / 2); 135 | } 136 | 137 | CGFloat DistanceBetweenPoint(CGPoint point1, CGPoint point2) 138 | { 139 | return sqrt((point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y)); 140 | } 141 | 142 | CGPoint CenterPointOf(CGPoint point1, CGPoint point2) 143 | { 144 | return CGPointMake((point1.x + point2.x) / 2, (point1.y + point2.y) / 2); 145 | } 146 | 147 | @end 148 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 354386191A695D3A00D8AFCE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 354386181A695D3A00D8AFCE /* main.m */; }; 11 | 3543861C1A695D3A00D8AFCE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3543861B1A695D3A00D8AFCE /* AppDelegate.m */; }; 12 | 354386221A695D3A00D8AFCE /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 354386211A695D3A00D8AFCE /* ViewController.m */; }; 13 | 354386251A695D3A00D8AFCE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 354386231A695D3A00D8AFCE /* Main.storyboard */; }; 14 | 354386271A695D3A00D8AFCE /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 354386261A695D3A00D8AFCE /* Images.xcassets */; }; 15 | 3543862A1A695D3A00D8AFCE /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 354386281A695D3A00D8AFCE /* LaunchScreen.xib */; }; 16 | 354386461A695EDD00D8AFCE /* UIBezierPath+LxThroughPointsBezier.m in Sources */ = {isa = PBXBuildFile; fileRef = 354386451A695EDD00D8AFCE /* UIBezierPath+LxThroughPointsBezier.m */; }; 17 | B64BD1DC1B497B77004489F4 /* PointView.m in Sources */ = {isa = PBXBuildFile; fileRef = B64BD1DB1B497B77004489F4 /* PointView.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 354386131A695D3900D8AFCE /* LxThroughPointsBezierDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LxThroughPointsBezierDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 354386171A695D3A00D8AFCE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 23 | 354386181A695D3A00D8AFCE /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 24 | 3543861A1A695D3A00D8AFCE /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | 3543861B1A695D3A00D8AFCE /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | 354386201A695D3A00D8AFCE /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | 354386211A695D3A00D8AFCE /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | 354386241A695D3A00D8AFCE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | 354386261A695D3A00D8AFCE /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 30 | 354386291A695D3A00D8AFCE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 31 | 354386441A695EDD00D8AFCE /* UIBezierPath+LxThroughPointsBezier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIBezierPath+LxThroughPointsBezier.h"; sourceTree = ""; }; 32 | 354386451A695EDD00D8AFCE /* UIBezierPath+LxThroughPointsBezier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIBezierPath+LxThroughPointsBezier.m"; sourceTree = ""; }; 33 | B64BD1DA1B497B77004489F4 /* PointView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PointView.h; sourceTree = ""; }; 34 | B64BD1DB1B497B77004489F4 /* PointView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PointView.m; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 354386101A695D3900D8AFCE /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 3543860A1A695D3900D8AFCE = { 49 | isa = PBXGroup; 50 | children = ( 51 | 354386151A695D3A00D8AFCE /* LxThroughPointsBezierDemo */, 52 | 354386141A695D3A00D8AFCE /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 354386141A695D3A00D8AFCE /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 354386131A695D3900D8AFCE /* LxThroughPointsBezierDemo.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 354386151A695D3A00D8AFCE /* LxThroughPointsBezierDemo */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 354386431A695EDD00D8AFCE /* LxThroughPointsBezier */, 68 | 3543861A1A695D3A00D8AFCE /* AppDelegate.h */, 69 | 3543861B1A695D3A00D8AFCE /* AppDelegate.m */, 70 | 354386201A695D3A00D8AFCE /* ViewController.h */, 71 | 354386211A695D3A00D8AFCE /* ViewController.m */, 72 | B64BD1DA1B497B77004489F4 /* PointView.h */, 73 | B64BD1DB1B497B77004489F4 /* PointView.m */, 74 | 354386161A695D3A00D8AFCE /* Supporting Files */, 75 | ); 76 | path = LxThroughPointsBezierDemo; 77 | sourceTree = ""; 78 | }; 79 | 354386161A695D3A00D8AFCE /* Supporting Files */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 354386281A695D3A00D8AFCE /* LaunchScreen.xib */, 83 | 354386231A695D3A00D8AFCE /* Main.storyboard */, 84 | 354386261A695D3A00D8AFCE /* Images.xcassets */, 85 | 354386171A695D3A00D8AFCE /* Info.plist */, 86 | 354386181A695D3A00D8AFCE /* main.m */, 87 | ); 88 | name = "Supporting Files"; 89 | sourceTree = ""; 90 | }; 91 | 354386431A695EDD00D8AFCE /* LxThroughPointsBezier */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 354386441A695EDD00D8AFCE /* UIBezierPath+LxThroughPointsBezier.h */, 95 | 354386451A695EDD00D8AFCE /* UIBezierPath+LxThroughPointsBezier.m */, 96 | ); 97 | name = LxThroughPointsBezier; 98 | path = ../../LxThroughPointsBezier; 99 | sourceTree = ""; 100 | }; 101 | /* End PBXGroup section */ 102 | 103 | /* Begin PBXNativeTarget section */ 104 | 354386121A695D3900D8AFCE /* LxThroughPointsBezierDemo */ = { 105 | isa = PBXNativeTarget; 106 | buildConfigurationList = 354386391A695D3A00D8AFCE /* Build configuration list for PBXNativeTarget "LxThroughPointsBezierDemo" */; 107 | buildPhases = ( 108 | 3543860F1A695D3900D8AFCE /* Sources */, 109 | 354386101A695D3900D8AFCE /* Frameworks */, 110 | 354386111A695D3900D8AFCE /* Resources */, 111 | ); 112 | buildRules = ( 113 | ); 114 | dependencies = ( 115 | ); 116 | name = LxThroughPointsBezierDemo; 117 | productName = LxThroughPointsBezierDemo; 118 | productReference = 354386131A695D3900D8AFCE /* LxThroughPointsBezierDemo.app */; 119 | productType = "com.apple.product-type.application"; 120 | }; 121 | /* End PBXNativeTarget section */ 122 | 123 | /* Begin PBXProject section */ 124 | 3543860B1A695D3900D8AFCE /* Project object */ = { 125 | isa = PBXProject; 126 | attributes = { 127 | LastUpgradeCheck = 0610; 128 | ORGANIZATIONNAME = "Gener-health-li.x"; 129 | TargetAttributes = { 130 | 354386121A695D3900D8AFCE = { 131 | CreatedOnToolsVersion = 6.1.1; 132 | }; 133 | }; 134 | }; 135 | buildConfigurationList = 3543860E1A695D3900D8AFCE /* Build configuration list for PBXProject "LxThroughPointsBezierDemo" */; 136 | compatibilityVersion = "Xcode 3.2"; 137 | developmentRegion = English; 138 | hasScannedForEncodings = 0; 139 | knownRegions = ( 140 | en, 141 | Base, 142 | ); 143 | mainGroup = 3543860A1A695D3900D8AFCE; 144 | productRefGroup = 354386141A695D3A00D8AFCE /* Products */; 145 | projectDirPath = ""; 146 | projectRoot = ""; 147 | targets = ( 148 | 354386121A695D3900D8AFCE /* LxThroughPointsBezierDemo */, 149 | ); 150 | }; 151 | /* End PBXProject section */ 152 | 153 | /* Begin PBXResourcesBuildPhase section */ 154 | 354386111A695D3900D8AFCE /* Resources */ = { 155 | isa = PBXResourcesBuildPhase; 156 | buildActionMask = 2147483647; 157 | files = ( 158 | 354386251A695D3A00D8AFCE /* Main.storyboard in Resources */, 159 | 3543862A1A695D3A00D8AFCE /* LaunchScreen.xib in Resources */, 160 | 354386271A695D3A00D8AFCE /* Images.xcassets in Resources */, 161 | ); 162 | runOnlyForDeploymentPostprocessing = 0; 163 | }; 164 | /* End PBXResourcesBuildPhase section */ 165 | 166 | /* Begin PBXSourcesBuildPhase section */ 167 | 3543860F1A695D3900D8AFCE /* Sources */ = { 168 | isa = PBXSourcesBuildPhase; 169 | buildActionMask = 2147483647; 170 | files = ( 171 | 354386461A695EDD00D8AFCE /* UIBezierPath+LxThroughPointsBezier.m in Sources */, 172 | 3543861C1A695D3A00D8AFCE /* AppDelegate.m in Sources */, 173 | 354386221A695D3A00D8AFCE /* ViewController.m in Sources */, 174 | B64BD1DC1B497B77004489F4 /* PointView.m in Sources */, 175 | 354386191A695D3A00D8AFCE /* main.m in Sources */, 176 | ); 177 | runOnlyForDeploymentPostprocessing = 0; 178 | }; 179 | /* End PBXSourcesBuildPhase section */ 180 | 181 | /* Begin PBXVariantGroup section */ 182 | 354386231A695D3A00D8AFCE /* Main.storyboard */ = { 183 | isa = PBXVariantGroup; 184 | children = ( 185 | 354386241A695D3A00D8AFCE /* Base */, 186 | ); 187 | name = Main.storyboard; 188 | sourceTree = ""; 189 | }; 190 | 354386281A695D3A00D8AFCE /* LaunchScreen.xib */ = { 191 | isa = PBXVariantGroup; 192 | children = ( 193 | 354386291A695D3A00D8AFCE /* Base */, 194 | ); 195 | name = LaunchScreen.xib; 196 | sourceTree = ""; 197 | }; 198 | /* End PBXVariantGroup section */ 199 | 200 | /* Begin XCBuildConfiguration section */ 201 | 354386371A695D3A00D8AFCE /* Debug */ = { 202 | isa = XCBuildConfiguration; 203 | buildSettings = { 204 | ALWAYS_SEARCH_USER_PATHS = NO; 205 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 206 | CLANG_CXX_LIBRARY = "libc++"; 207 | CLANG_ENABLE_MODULES = YES; 208 | CLANG_ENABLE_OBJC_ARC = YES; 209 | CLANG_WARN_BOOL_CONVERSION = YES; 210 | CLANG_WARN_CONSTANT_CONVERSION = YES; 211 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 212 | CLANG_WARN_EMPTY_BODY = YES; 213 | CLANG_WARN_ENUM_CONVERSION = YES; 214 | CLANG_WARN_INT_CONVERSION = YES; 215 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 216 | CLANG_WARN_UNREACHABLE_CODE = YES; 217 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 218 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 219 | COPY_PHASE_STRIP = NO; 220 | ENABLE_STRICT_OBJC_MSGSEND = YES; 221 | GCC_C_LANGUAGE_STANDARD = gnu99; 222 | GCC_DYNAMIC_NO_PIC = NO; 223 | GCC_OPTIMIZATION_LEVEL = 0; 224 | GCC_PREPROCESSOR_DEFINITIONS = ( 225 | "DEBUG=1", 226 | "$(inherited)", 227 | ); 228 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 229 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 230 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 231 | GCC_WARN_UNDECLARED_SELECTOR = YES; 232 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 233 | GCC_WARN_UNUSED_FUNCTION = YES; 234 | GCC_WARN_UNUSED_VARIABLE = YES; 235 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 236 | MTL_ENABLE_DEBUG_INFO = YES; 237 | ONLY_ACTIVE_ARCH = YES; 238 | SDKROOT = iphoneos; 239 | TARGETED_DEVICE_FAMILY = "1,2"; 240 | }; 241 | name = Debug; 242 | }; 243 | 354386381A695D3A00D8AFCE /* Release */ = { 244 | isa = XCBuildConfiguration; 245 | buildSettings = { 246 | ALWAYS_SEARCH_USER_PATHS = NO; 247 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 248 | CLANG_CXX_LIBRARY = "libc++"; 249 | CLANG_ENABLE_MODULES = YES; 250 | CLANG_ENABLE_OBJC_ARC = YES; 251 | CLANG_WARN_BOOL_CONVERSION = YES; 252 | CLANG_WARN_CONSTANT_CONVERSION = YES; 253 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 254 | CLANG_WARN_EMPTY_BODY = YES; 255 | CLANG_WARN_ENUM_CONVERSION = YES; 256 | CLANG_WARN_INT_CONVERSION = YES; 257 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 258 | CLANG_WARN_UNREACHABLE_CODE = YES; 259 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 260 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 261 | COPY_PHASE_STRIP = YES; 262 | ENABLE_NS_ASSERTIONS = NO; 263 | ENABLE_STRICT_OBJC_MSGSEND = YES; 264 | GCC_C_LANGUAGE_STANDARD = gnu99; 265 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 266 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 267 | GCC_WARN_UNDECLARED_SELECTOR = YES; 268 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 269 | GCC_WARN_UNUSED_FUNCTION = YES; 270 | GCC_WARN_UNUSED_VARIABLE = YES; 271 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 272 | MTL_ENABLE_DEBUG_INFO = NO; 273 | SDKROOT = iphoneos; 274 | TARGETED_DEVICE_FAMILY = "1,2"; 275 | VALIDATE_PRODUCT = YES; 276 | }; 277 | name = Release; 278 | }; 279 | 3543863A1A695D3A00D8AFCE /* Debug */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 283 | INFOPLIST_FILE = LxThroughPointsBezierDemo/Info.plist; 284 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 285 | PRODUCT_NAME = "$(TARGET_NAME)"; 286 | }; 287 | name = Debug; 288 | }; 289 | 3543863B1A695D3A00D8AFCE /* Release */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 293 | INFOPLIST_FILE = LxThroughPointsBezierDemo/Info.plist; 294 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 295 | PRODUCT_NAME = "$(TARGET_NAME)"; 296 | }; 297 | name = Release; 298 | }; 299 | /* End XCBuildConfiguration section */ 300 | 301 | /* Begin XCConfigurationList section */ 302 | 3543860E1A695D3900D8AFCE /* Build configuration list for PBXProject "LxThroughPointsBezierDemo" */ = { 303 | isa = XCConfigurationList; 304 | buildConfigurations = ( 305 | 354386371A695D3A00D8AFCE /* Debug */, 306 | 354386381A695D3A00D8AFCE /* Release */, 307 | ); 308 | defaultConfigurationIsVisible = 0; 309 | defaultConfigurationName = Release; 310 | }; 311 | 354386391A695D3A00D8AFCE /* Build configuration list for PBXNativeTarget "LxThroughPointsBezierDemo" */ = { 312 | isa = XCConfigurationList; 313 | buildConfigurations = ( 314 | 3543863A1A695D3A00D8AFCE /* Debug */, 315 | 3543863B1A695D3A00D8AFCE /* Release */, 316 | ); 317 | defaultConfigurationIsVisible = 0; 318 | defaultConfigurationName = Release; 319 | }; 320 | /* End XCConfigurationList section */ 321 | }; 322 | rootObject = 3543860B1A695D3900D8AFCE /* Project object */; 323 | } 324 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // LxThroughPointsBezierDemo 4 | // 5 | 6 | #import 7 | 8 | @interface AppDelegate : UIResponder 9 | 10 | @property (strong, nonatomic) UIWindow *window; 11 | 12 | @end 13 | 14 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // LxThroughPointsBezierDemo 4 | // 5 | 6 | #import "AppDelegate.h" 7 | 8 | @interface AppDelegate () 9 | 10 | @end 11 | 12 | @implementation AppDelegate 13 | 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 16 | 17 | return YES; 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/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 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.gener-tech-bj.LxFTPRequestDemo.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/LxThroughPointsBezierDemo.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/LxThroughPointsBezierDemo.xcdatamodeld/LxThroughPointsBezierDemo.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/PointView.h: -------------------------------------------------------------------------------- 1 | // 2 | // PointView.h 3 | // LxThroughPointsBezierDemo 4 | // 5 | 6 | #import 7 | 8 | @interface PointView : UIControl 9 | 10 | + (PointView *)aInstance; 11 | 12 | @property (nonatomic,copy) void (^dragCallBack)(PointView * pointView); 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/PointView.m: -------------------------------------------------------------------------------- 1 | // 2 | // PointView.m 3 | // LxThroughPointsBezierDemo 4 | // 5 | 6 | #import "PointView.h" 7 | 8 | static CGFloat const RADIUS = 5; 9 | 10 | @implementation PointView 11 | 12 | + (PointView *)aInstance 13 | { 14 | PointView * aInstance = [[self alloc]initWithFrame:(CGRect){CGPointZero, CGSizeMake(RADIUS * 2, RADIUS * 2)}]; 15 | aInstance.layer.cornerRadius = RADIUS; 16 | aInstance.layer.masksToBounds = YES; 17 | aInstance.backgroundColor = [UIColor magentaColor]; 18 | [aInstance addTarget:aInstance action:@selector(touchDragInside:withEvent:) forControlEvents:UIControlEventTouchDragInside]; 19 | 20 | return aInstance; 21 | } 22 | 23 | - (void)touchDragInside:(PointView *)pointView withEvent:(UIEvent *)event 24 | { 25 | pointView.center = [[[event allTouches]anyObject] locationInView:self.superview]; 26 | 27 | if (self.dragCallBack) { 28 | self.dragCallBack(self); 29 | } 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // LxThroughPointsBezierDemo 4 | // 5 | 6 | #import 7 | 8 | @interface ViewController : UIViewController 9 | 10 | @end 11 | 12 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // LxThroughPointsBezierDemo 4 | // 5 | 6 | #import "ViewController.h" 7 | #import "PointView.h" 8 | #import "UIBezierPath+LxThroughPointsBezier.h" 9 | 10 | @interface ViewController () 11 | 12 | @end 13 | 14 | @implementation ViewController 15 | { 16 | UIBezierPath * _curve; 17 | CAShapeLayer * _shapeLayer; 18 | NSMutableArray * _pointViewArray; 19 | } 20 | 21 | - (void)viewDidLoad 22 | { 23 | [super viewDidLoad]; 24 | 25 | UISlider * slider = [[UISlider alloc]init]; 26 | slider.minimumValue = 0; 27 | slider.maximumValue = 1.4; 28 | slider.value = 0.7; 29 | [slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged]; 30 | [self.view addSubview:slider]; 31 | 32 | slider.translatesAutoresizingMaskIntoConstraints = NO; 33 | 34 | NSArray * sliderHorizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[slider]-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(slider)]; 35 | NSArray * sliderVerticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-topMargin-[slider(==sliderHeight)]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:@{@"sliderHeight":@6, @"topMargin":@60} views:NSDictionaryOfVariableBindings(slider)]; 36 | [self.view addConstraints:sliderHorizontalConstraints]; 37 | [self.view addConstraints:sliderVerticalConstraints]; 38 | 39 | 40 | _pointViewArray = [[NSMutableArray alloc]init]; 41 | 42 | NSMutableArray * pointValueArray = [NSMutableArray array]; 43 | 44 | ViewController * __weak weakSelf = self; 45 | 46 | for (int i = 0; i < 6; i++) { 47 | 48 | PointView * pointView = [PointView aInstance]; 49 | 50 | pointView.center = CGPointMake(i * 60 + 30, 420); 51 | pointView.dragCallBack = ^(PointView * pv){ 52 | 53 | ViewController * __strong strongSelf = weakSelf; 54 | [strongSelf sliderValueChanged:slider]; 55 | }; 56 | 57 | [self.view addSubview:pointView]; 58 | [_pointViewArray addObject:pointView]; 59 | 60 | [pointValueArray addObject:[NSValue valueWithCGPoint:pointView.center]]; 61 | } 62 | 63 | NSValue * firstPointValue = pointValueArray.firstObject; 64 | 65 | _curve = [UIBezierPath bezierPath]; 66 | [_curve moveToPoint:firstPointValue.CGPointValue]; 67 | [_curve addBezierThroughPoints:pointValueArray]; 68 | 69 | _shapeLayer = [CAShapeLayer layer]; 70 | _shapeLayer.strokeColor = [UIColor blueColor].CGColor; 71 | _shapeLayer.fillColor = nil; 72 | _shapeLayer.lineWidth = 3; 73 | _shapeLayer.path = _curve.CGPath; 74 | _shapeLayer.lineCap = kCALineCapRound; 75 | [self.view.layer addSublayer:_shapeLayer]; 76 | } 77 | 78 | - (void)sliderValueChanged:(UISlider *)slider 79 | { 80 | [_curve removeAllPoints]; 81 | _curve.contractionFactor = slider.value; 82 | 83 | PointView * firstPointView = _pointViewArray.firstObject; 84 | 85 | [_curve moveToPoint:firstPointView.center]; 86 | 87 | NSMutableArray * pointValueArray = [NSMutableArray array]; 88 | for (PointView * pointView in _pointViewArray) { 89 | 90 | [pointValueArray addObject:[NSValue valueWithCGPoint:pointView.center]]; 91 | } 92 | [_curve addBezierThroughPoints:pointValueArray]; 93 | 94 | _shapeLayer.path = _curve.CGPath; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // LxThroughPointsBezierDemo 4 | // 5 | // Created by Gener-health-li.x on 15/1/16. 6 | // Copyright (c) 2015年 Gener-health-li.x. 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LxThroughPointsBezier 2 | Draw a smooth bezier through several points you designated. The curve‘s bend level is adjustable. 3 | Installation 4 | ------------ 5 | You only need drag UIBezierPath+LxThroughPointsBezier.h and UIBezierPath+LxThroughPointsBezier.m to your project. 6 | 7 | Podfile 8 | ------------ 9 | pod 'LxThroughPointsBezier', '~> 1.0.0' 10 | 11 | Support 12 | ------------ 13 | Minimum support iOS version: iOS 5.0 14 | How to use 15 | ----------- 16 | ```objc 17 | #import "UIBezierPath+LxThroughPointsBezier.h" 18 | 19 | CGPoint point1 = CGPointMake(30, 180); 20 | CGPoint point2 = CGPointMake(90, 120); 21 | CGPoint point3 = CGPointMake(120, 200); 22 | CGPoint point4 = CGPointMake(160, 240); 23 | CGPoint point5 = CGPointMake(210, 160); 24 | CGPoint point6 = CGPointMake(240, 300); 25 | CGPoint point7 = CGPointMake(290, 140); 26 | 27 | NSValue * point1Value = [NSValue valueWithCGPoint:point1]; 28 | NSValue * point2Value = [NSValue valueWithCGPoint:point2]; 29 | NSValue * point3Value = [NSValue valueWithCGPoint:point3]; 30 | NSValue * point4Value = [NSValue valueWithCGPoint:point4]; 31 | NSValue * point5Value = [NSValue valueWithCGPoint:point5]; 32 | NSValue * point6Value = [NSValue valueWithCGPoint:point6]; 33 | NSValue * point7Value = [NSValue valueWithCGPoint:point7]; 34 | 35 | _pointArray = [NSMutableArray array]; 36 | [_pointArray addObjectsFromArray:@[point1Value, point2Value, point3Value, point4Value, point5Value, point6Value, point7Value]]; 37 | 38 | _curve = [UIBezierPath bezierPath]; 39 | _curve.contractionFactor = 0.6; 40 | [_curve moveToPoint:point1]; 41 | [_curve addBezierThroughPoints:_pointArray]; 42 | 43 | _shapeLayer = [CAShapeLayer layer]; 44 | _shapeLayer.strokeColor = [UIColor blueColor].CGColor; 45 | _shapeLayer.fillColor = nil; 46 | _shapeLayer.lineWidth = 3; 47 | _shapeLayer.path = _curve.CGPath; 48 | [_view.layer addSublayer:_shapeLayer]; 49 | ``` 50 | Effect 51 | ----------- 52 | * ![demo](demo.gif) 53 | 54 | Be careful 55 | ----------- 56 | The good bend level is about 0.6 ~ 0.8. The default and recommended value is 0.7. 57 | You must wrap CGPoint struct to NSValue object, and give at least 1 point for drawing the curve. 58 | License 59 | ----------- 60 | LxThroughPointsBezier is available under the Apache License 2.0. See the LICENSE file for more info. 61 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeveloperLx/LxThroughPointsBezier/318e11b01da1e1f607746bb3c30bfc822591f9ea/demo.gif --------------------------------------------------------------------------------