2

UIStepperの自動リピート動作を変更することを希望するクライアントがいます。

ユーザーがステッパーの+ボタンなどを押し続けると、ステッパーの値は0.5秒ごとに1の割合で増加し始め、約3秒後に値ははるかに急速に変化し始めます。

これがどのように機能するかを変更する方法はありますか?たとえば、ユーザーがタップして押したままにすると、値がすぐに速く増加しますか?

UISteppedのドキュメントを見ましたが、これに関しては何もわかりませんでしたが、IBActionなどを使用してこれを行う方法があるかどうか疑問に思いました。

4

2 に答える 2

8

まず、ステッパーに2つのアクションを追加します。

[theStepper addTarget:self action:@selector(stepperTapped:) forControlEvents:UIControlEventTouchDown];
[theStepper addTarget:self action:@selector(stepperValueChanged:) forControlEvents:UIControlEventValueChanged];

これらのアクションは次のようになります。

- (IBAction)stepperTapped:(id)sender {
self.myStepper.stepValue = 1;
self.myStartTime = CFAbsoluteTimeGetCurrent();

}

- (IBAction)stepperValueChanged:(id)sender {
self.myStepper.stepValue = [self stepValueForTimeSince:self.myStepperStartTime];
// handle the value change here

}

魔法のコードは次のとおりです。

- (double)stepValueForTimeSince:(CFAbsoluteTime)aStartTime {
double theStepValue = 1;
CFAbsoluteTime  theElapsedTime  = CFAbsoluteTimeGetCurrent() - aStartTime;

if (theElapsedTime > 6.0) {
    theStepValue = 1000;
} else if (theElapsedTime > 4.0) {
    theStepValue = 100;
} else if (theElapsedTime > 2.0) {
    theStepValue = 10;
}

return theStepValue;

}

于 2013-07-25T19:54:37.297 に答える
1

この動作を変更することはできないようです。カスタムUIButtonを使用するのが最善の解決策です。

于 2012-03-29T18:17:11.453 に答える