2012-03-21 6 views
2

私はUIStepperの自動反復動作を変更したいクライアントがあります。UIStepperの自動反復動作の変更

ユーザーがタッチを選択してステッパーの+ボタンを押した場合、ステッパーの値は0.5秒ごとに1の割合で増加し始め、約3秒後に値がさらに大きく変化し始めます急速に。

これはどのように動作するのですか?ユーザーがタップして保持した場合など、値がすぐに速くなるように変更しますか?

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

+1

カスタムボタンの代わりに、 'UIStepper'を使用 – tipycalFlow

答えて

6

まず、あなたのステッパー用の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; 

}

1

この動作を変更することはできないようで、カスタムUIButtonsを使用することが最適なソリューションです。

関連する問題