Skip to content

Commit 0c85a8e

Browse files
author
li.x
committed
demo modify
1 parent d0061fa commit 0c85a8e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

LxThroughPointsBezierDemo/LxThroughPointsBezierDemo/ViewController.m

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ - (void)viewDidLoad {
4040
[_pointArray addObjectsFromArray:@[point1Value, point2Value, point3Value, point4Value, point5Value, point6Value, point7Value]];
4141

4242
_curve = [UIBezierPath bezierPath];
43-
[_curve addCurvesThroughPoints:_pointArray];
43+
[_curve moveToPoint:point1];
44+
[_curve addBezierThroughPoints:_pointArray];
4445

4546
[self drawPoint:point1];
4647
[self drawPoint:point2];
@@ -58,12 +59,18 @@ - (void)viewDidLoad {
5859
_shapeLayer.lineCap = kCALineCapRound;
5960
[self.view.layer addSublayer:_shapeLayer];
6061

61-
UISlider * slider = [[UISlider alloc]initWithFrame:CGRectMake(20, 84, 280, 6)];
62+
UISlider * slider = [[UISlider alloc]init];
6263
slider.minimumValue = 0;
6364
slider.maximumValue = 1.4;
6465
slider.value = 0.7;
66+
slider.translatesAutoresizingMaskIntoConstraints = NO;
6567
[slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
6668
[self.view addSubview:slider];
69+
70+
NSArray * sliderHorizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[slider]-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(slider)];
71+
NSArray * sliderVerticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-topMargin-[slider(==sliderHeight)]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:@{@"sliderHeight":@6, @"topMargin":@60} views:NSDictionaryOfVariableBindings(slider)];
72+
[self.view addConstraints:sliderHorizontalConstraints];
73+
[self.view addConstraints:sliderVerticalConstraints];
6774
}
6875

6976
- (void)drawPoint:(CGPoint)point
@@ -81,7 +88,12 @@ - (void)sliderValueChanged:(UISlider *)slider
8188
{
8289
[_curve removeAllPoints];
8390
_curve.contractionFactor = slider.value;
84-
[_curve addCurvesThroughPoints:_pointArray];
91+
92+
NSValue * point0Value = _pointArray[0];
93+
CGPoint point0 = [point0Value CGPointValue];
94+
95+
[_curve moveToPoint:point0];
96+
[_curve addBezierThroughPoints:_pointArray];
8597

8698
_shapeLayer.path = _curve.CGPath;
8799
}

0 commit comments

Comments
 (0)