まず、あなたのステッパー用の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;
}
カスタムボタンの代わりに、 'UIStepper'を使用 – tipycalFlow