Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CADisplayLink retain cycle. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions Waver/Source/Waver.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ - (void)awakeFromNib
[self setup];
}

- (void)removeFromSuperview
{
[_displayLink invalidate];
_displayLink = nil;
}

- (void)setup
{
self.waves = [NSMutableArray new];
Expand Down Expand Up @@ -121,16 +127,13 @@ - (void)updateMeters
UIGraphicsBeginImageContext(self.frame.size);

for(int i=0; i < self.numberOfWaves; i++) {

UIBezierPath *wavelinePath = [UIBezierPath bezierPath];

// Progress is a value between 1.0 and -0.5, determined by the current wave idx, which is used to alter the wave's amplitude.
CGFloat progress = 1.0f - (CGFloat)i / self.numberOfWaves;
CGFloat normedAmplitude = (1.5f * progress - 0.5f) * self.amplitude;


for(CGFloat x = 0; x<self.waveWidth + self.density; x += self.density) {

//Thanks to https://github.com/stefanceriu/SCSiriWaveformView
// We use a parable to scale the sinus wave, that has its peak in the middle of the view.
CGFloat scaling = -pow(x / self.waveMid - 1, 2) + 1; // make center bigger
Expand All @@ -151,10 +154,4 @@ - (void)updateMeters

UIGraphicsEndImageContext();
}

- (void)dealloc
{
[_displayLink invalidate];
}

@end