@@ -40,7 +40,8 @@ - (void)viewDidLoad {
40
40
[_pointArray addObjectsFromArray: @[point1Value, point2Value, point3Value, point4Value, point5Value, point6Value, point7Value]];
41
41
42
42
_curve = [UIBezierPath bezierPath ];
43
- [_curve addCurvesThroughPoints: _pointArray];
43
+ [_curve moveToPoint: point1];
44
+ [_curve addBezierThroughPoints: _pointArray];
44
45
45
46
[self drawPoint: point1];
46
47
[self drawPoint: point2];
@@ -58,12 +59,18 @@ - (void)viewDidLoad {
58
59
_shapeLayer.lineCap = kCALineCapRound ;
59
60
[self .view.layer addSublayer: _shapeLayer];
60
61
61
- UISlider * slider = [[UISlider alloc ]initWithFrame: CGRectMake ( 20 , 84 , 280 , 6 ) ];
62
+ UISlider * slider = [[UISlider alloc ]init ];
62
63
slider.minimumValue = 0 ;
63
64
slider.maximumValue = 1.4 ;
64
65
slider.value = 0.7 ;
66
+ slider.translatesAutoresizingMaskIntoConstraints = NO ;
65
67
[slider addTarget: self action: @selector (sliderValueChanged: ) forControlEvents: UIControlEventValueChanged];
66
68
[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];
67
74
}
68
75
69
76
- (void )drawPoint : (CGPoint)point
@@ -81,7 +88,12 @@ - (void)sliderValueChanged:(UISlider *)slider
81
88
{
82
89
[_curve removeAllPoints ];
83
90
_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];
85
97
86
98
_shapeLayer.path = _curve.CGPath ;
87
99
}
0 commit comments