动画不允许按钮可点击

时间:2014-12-18 22:04:14

标签: ios

录制时我在麦克风按钮上实现了闪烁效果。现在它不允许我点击停止。我无法找出问题的根源

-

 (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 个答案:

答案 0 :(得分:0)

问题在于,当您将alpha设置为0时,iOS会认为您希望隐藏视图,因此会禁用该视图的触摸事件。避免此问题的最简单方法是将alpha设置为较低的值(似乎有一个阈值,有些人说0.1可以,但尝试一些值)。图像不会完全消失(在您的情况下可能没问题,因为它正在振荡)但触摸将被识别。