If you feel that the image changes look jerky, you better apply animation to them. By the way, you do not need to install nil in imgViewRecordAnimation.image , because you are setting the right image after all the time that will lead to an unnecessary delay. You can also do all if else statements if, otherwise, every time all if statements are executed.
Getting started, you can simply follow the link sent by @MileAtNobel. Or, if you do not want to make a lot of code changes, you can apply a simple animation in the backgroundColor property. You can also delete the timer, check the code below and see if the code works. I also tried to optimize the code with close similarities, hope this improves performance.
BOOL flagToContinue ; //assign NO to this flag to stop updating the images -(void)levelTimerCallback { NSLog(@"Volume Logic Begins") ;//Volume level logic begins [self.audioRecorder updateMeters]; const double ALPHA = 0.05; double peakPowerForChannel = pow(10, (0.05 * [self.audioRecorder peakPowerForChannel:0])); lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults ; NSLog(@"Volume Logic ends") ;//Volume level logic ends [UIView animateWithDuration:0.001f delay:0.0f options: UIViewAnimationOptionCurveLinear animations:^{ mgViewRecordAnimation.backgroundColor = [UIColor colorWithPatternImage:[NSString stringWithFormat:@"anim%d", (int)ceil(lowPassResults * 20)]]; } completion:^(BOOL finished) { if(finished && flagToContinue) [self levelTimerCallback]; }]; }
source share