我有一个客户想要我修改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