我有一個客戶想要我修改UIStepper的自動重複行爲。修改UIStepper自動重複行爲
如果用戶選擇觸摸並保持說步進器的+按鈕,步進器的值開始以每半秒左右的速率增加,然後在約3秒後,值開始變化得更多迅速。
有沒有辦法修改它的工作方式,例如,如果用戶點擊並保持,值會立即以更快的速度增加。
我已經看過UIStepped文檔,我沒有看到任何關於這個,但我想知道是否有辦法通過IBAction或其他方式做到這一點。
我有一個客戶想要我修改UIStepper的自動重複行爲。修改UIStepper自動重複行爲
如果用戶選擇觸摸並保持說步進器的+按鈕,步進器的值開始以每半秒左右的速率增加,然後在約3秒後,值開始變化得更多迅速。
有沒有辦法修改它的工作方式,例如,如果用戶點擊並保持,值會立即以更快的速度增加。
我已經看過UIStepped文檔,我沒有看到任何關於這個,但我想知道是否有辦法通過IBAction或其他方式做到這一點。
首先,添加兩個動作爲您步進:
[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;
}
看來,這是不可能修改此行爲,並使用自定義UIButtons是最好的解決方案。
使用,而不是一個'UIStepper'您的自定義按鈕 – tipycalFlow 2012-03-21 17:25:39