1

私は音楽プレーヤーアプリケーションを作成しています。1つのボタンから2つのアクションを呼び出す必要があります。1つはイベント内でタッチアップして次のトラックにスキップし、もう1つは「長押し」の場合に現在のトラックを早送りします。どのイベントがこの長押しを指しているのかわかりません。タッチダウンだと思いましたが、ボタンを押している間だけ機能しました。ボタンを離すと、トラックがスキップされて次のアイテムに移動しました。plsヘルプ

AVAudioPlayer *appSoundPlayer;// declared in .h file

mファイルでは、メソッドは次のとおりです。

-(void)seekForwards{
NSTimeInterval timex;
timex = appSoundPlayer.currentTime;
        timex = timex+5; // forward 5 secs

        appSoundPlayer.currentTime = timex;
        timex = 0;
}
4

2 に答える 2

4

個人的には、ビューコントローラーまたはボタンサブクラス内の整数でボタンの状態を追跡するだけです。ボタンの動作を追跡すると、各アクションの動作を制御できます。あなたの.hファイルに次のようなものを入れてください:

enum {
    MyButtonScanning,
    MyButtonStalling,
    MyButtonIdle
};



@interface YourClass : UIViewController {
    NSInteger buttonModeAt;
}
@property (nonatomic) NSInteger buttonModeAt;
-(IBAction)buttonPushedDown:(id)sender;
-(void)tryScanForward:(id)sender;
-(IBAction)buttonReleasedOutside:(id)sender;
-(IBAction)buttonReleasedInside:(id)sender;
@end

そして、あなたの .m ファイルに次のものをいくつか入れてください:

@implementation YourClass
///in your .m file
@synthesize buttonModeAt;


///link this to your button's touch down
-(IBAction)buttonPushedDown:(id)sender {
    buttonModeAt = MyButtonStalling;
    [self performSelector:@selector(tryScanForward:) withObject:nil afterDelay:1.0];
}

-(void)tryScanForward:(id)sender {
    if (buttonModeAt == MyButtonStalling) {
        ///the button was not released so let's start scanning
        buttonModeAt = MyButtonScanning;

        ////your actual scanning code or a call to it can go here
        [self startScanForward];
    }
}

////you will link this to the button's touch up outside
-(IBAction)buttonReleasedOutside:(id)sender {
    if (buttonModeAt == MyButtonScanning) {
        ///they released the button and stopped scanning forward
        [self stopScanForward];
    } else if (buttonModeAt == MyButtonStalling) {
        ///they released the button before the delay period finished
        ///but it was outside, so we do nothing
    }

    self.buttonModeAt = MyButtonIdle;
}

////you will link this to the button's touch up inside
-(IBAction)buttonReleasedInside:(id)sender {
    if (buttonModeAt == MyButtonScanning) {
        ///they released the button and stopped scanning forward
        [self stopScanForward];
    } else if (buttonModeAt == MyButtonStalling) {
        ///they released the button before the delay period finished so we skip forward
        [self skipForward];
    }

    self.buttonModeAt = MyButtonIdle;

}

その後、ボタンのアクションを IBactions の前のコメントに記載した内容にリンクするだけです。私はこれをテストしていませんが、動作するはずです。

于 2009-12-18T07:05:44.070 に答える
0

ボタンのクラスをサブクラス化し、UIResponder のメソッドを少しいじることができます。たとえば、touchesBeganメソッドでは、タイマーを起動してメソッドを呼び出すことができます。これにより、ファイルがスローされ、toucesEndedメソッドでこのタイマーが無効になります

于 2009-12-18T07:08:34.730 に答える