0

I have implemented a flashing effect on microphone button while it is recording. Now it does not allow me to click to stop. I could not able to figure out the root of the problem

-

 (IBAction)microButton:(id)sender {

    if(counter%2==0)
    {
        if (!recorder.recording) {

            AVAudioSession *session = [AVAudioSession sharedInstance];
            [session setActive:YES error:nil];
            [micImage setBackgroundImage:[UIImage imageNamed:@"ico_mic_on.png"] forState:UIControlStateNormal];
            [UIView animateWithDuration:0.5
                                  delay:0.0
                                options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction
                             animations:^{
                                 self.micImage.alpha = 0.0f;
                             }
                             completion:^(BOOL finished){
                             }];

            // Start recording
            [recorder record];
        }
        counter=counter+1;

    }
    else{
        [recorder stop];

        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession setActive:NO error:nil];
            counter=counter+1;
        [micImage setBackgroundImage:[UIImage imageNamed:@"ico_mic.png"] forState:UIControlStateNormal];
        self.micImage.alpha = 1.0f;

        [UIView animateWithDuration:0.1
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
                         animations:^{
                             self.micImage.alpha = 1.0f;
                         }
                         completion:^(BOOL finished){
                         }];
    }
}

1 Answers1

0

The problem is that when you set the alpha to 0, iOS thinks you want the view to be hidden, and hence disables touch events for it. The easiest way to avoid the problem will be to set alpha to a low value (there appears to be a threshold, some say 0.1 is OK, but try a few values). The image will not quite disappear (which is probably OK in your case, since it is oscillating) but the touches will be recognised.

pbasdf
  • 21,386
  • 4
  • 43
  • 75