2

だから私は、右から左にぐらつき、最大角度に達したときに音を鳴らすために、ベースのアンカーポイントとほとんど同じ線であるビューを作成するつもりです。(メトロノームアームの実装)

私の方法は次のとおりです。

-(void)goForward :(UIView*)view{

CGAffineTransform rightWobble = CGAffineTransformMakeRotation(RADIANS(120));

[UIView animateWithDuration:duration animations:^{

    view.transform=rightWobble;

} completion:^(BOOL finished) {
    NSLog(@"go back  duration : %f",duration);

    if (isWobbling) {
        [self goBack:view];
        [self performSelector:@selector(playMetronomeSound) withObject:nil afterDelay:duration];  
    }
    else if (!isWobbling){
            [self stopWobbling];
            [self performSelector:@selector(stopMetronomeSound) withObject:nil afterDelay:0.0];
    }

}];  }

-(void)goBack :(UIView*)view{


CGAffineTransform leftWobble = CGAffineTransformMakeRotation(RADIANS(60));

[UIView animateWithDuration:duration animations:^{

    view.transform = leftWobble;

} completion:^(BOOL finished) {
    NSLog(@"go forward  duration: %f",duration);

    if (isWobbling) {
        [self goForward:view];
        [self performSelector:@selector(playMetronomeSound) withObject:nil afterDelay:duration];
        }
    else if (!isWobbling){
        [self stopWobbling];
        [self performSelector:@selector(stopMetronomeSound) withObject:nil afterDelay:0.0];
}];  }

-(void) stopWobbling{

[UIView animateWithDuration:0.1 animations:^{
    metronomeSlider.transform = vertical;
    [self stopMetronomeSound];
}]; }

-(void) playMetronomeSound{

        alSourcePlay(mySoundSource);
}

-(void) stopMetronomeSound{

        alSourceStop(mySoundSource);
}

duration 変数は、アニメーションの長さを決定します。次のような再生ボタンを押すと、アニメーションが発生します。

-(void)playButtonAction {
if (_metronomeIsAnimatingAndPLaying == NO)
{
    [self goForward:metronomeSlider];

    [_playButton setImage:[UIImage imageNamed:@"stop"] forState:UIControlStateNormal];
    [self performSelector:@selector(playMetronomeSound) withObject:nil afterDelay:duration];

    _metronomeIsAnimatingAndPLaying = YES;
    isWobbling = YES;

    NSLog(@"DURATION IS : %f",duration);

}

else if (_metronomeIsAnimatingAndPLaying == YES)
{
    [_playButton setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];

    [self stopWobbling];

    _metronomeIsAnimatingAndPLaying = NO;
    isWobbling = NO;
}   }

私の問題は、再生/停止ボタンを押してアニメーションを停止し、ビューを90度の角度に戻すたびに発生しますが、再生することを意図していない余分なティック音が再生されます。

これを修正する方法はありますか?

事前にありがとう

スクリーンショットの更新:

ここに画像の説明を入力

4

1 に答える 1