|
@@ -11,6 +11,10 @@
|
|
|
|
|
|
@property (nonatomic, strong) CAGradientLayer *combinedGradientLayer;
|
|
|
|
|
|
+@property (nonatomic, strong) CAShapeLayer *combinedMaskLayer;
|
|
|
+
|
|
|
+@property (nonatomic, assign) CGFloat xIncrement;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation KSSpectrumView
|
|
@@ -35,7 +39,8 @@
|
|
|
- (void)setupView {
|
|
|
self.barWidth = 3.0;
|
|
|
self.space = 1.0;
|
|
|
-
|
|
|
+ self.xIncrement = self.barWidth + self.space;
|
|
|
+
|
|
|
self.combinedGradientLayer = [CAGradientLayer layer];
|
|
|
self.combinedGradientLayer.colors = @[
|
|
|
(__bridge id)HexRGBAlpha(0xffffff, 1.0f).CGColor,
|
|
@@ -43,6 +48,8 @@
|
|
|
];
|
|
|
self.combinedGradientLayer.locations = @[@0.6, @1.0];
|
|
|
[self.layer addSublayer:self.combinedGradientLayer];
|
|
|
+
|
|
|
+ self.combinedMaskLayer = [CAShapeLayer layer];
|
|
|
}
|
|
|
|
|
|
- (void)resetLayer {
|
|
@@ -71,12 +78,11 @@
|
|
|
CGFloat middleY = viewHeight / 2.0;
|
|
|
CGFloat barHeight = (viewHeight) / 2.0;
|
|
|
CGFloat cornerRadius = viewWidth / 2.0f;
|
|
|
- CGFloat xIncrement = self.barWidth + self.space;
|
|
|
UIBezierPath *combinedPath = [UIBezierPath bezierPath];
|
|
|
|
|
|
// Left channel
|
|
|
for (NSUInteger i = 0; i < spectraCount; i++) {
|
|
|
- CGFloat x = i * xIncrement + self.space;
|
|
|
+ CGFloat x = i * self.xIncrement + self.space;
|
|
|
CGFloat amplitudeValue = combinedSpectrum[i].floatValue;
|
|
|
CGFloat height = amplitudeValue * barHeight;
|
|
|
CGFloat y = middleY - height/2.0; // Centered vertically
|
|
@@ -87,10 +93,9 @@
|
|
|
}
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- CAShapeLayer *combinedMaskLayer = [CAShapeLayer layer];
|
|
|
- combinedMaskLayer.path = combinedPath.CGPath;
|
|
|
+ self.combinedMaskLayer.path = combinedPath.CGPath;
|
|
|
self.combinedGradientLayer.frame = CGRectMake(0, 0, viewWidth, viewHeight);
|
|
|
- self.combinedGradientLayer.mask = combinedMaskLayer;
|
|
|
+ self.combinedGradientLayer.mask = self.combinedMaskLayer;
|
|
|
self.isModify = NO;
|
|
|
});
|
|
|
});
|