当我更改UISlider的maximumValue属性时,UISlider的擦除不会重新定位。我通过清理UISlider A来动态更改UISlider B的maximumValue属性。因此,当UISlider A更改为1时,UISlider B具有maximumValue+=1。UISlider B应该自动更新其擦除位置,但它没有。如果我随后按下UISlider B scrub,它会更新。
这个问题的解决方案是什么?
发布于 2011-04-13 10:56:34
我遇到了这个问题:当以编程方式设置UISlider时,即使您显式调用setValue,maximumValue thumb也不会在轨道上重新定位自己。例如:
// Setup:
UISlider *a = [[UISlider alloc] init];
a.minimumValue = 1.00;
a.maximumValue = 100.00;
[a setValue: 50.00];
/* CORRECT: The thumb is in the centre of the track, at position "50.00":
1 --------------------------- () --------------------------- 100
a.value == 50
*/
// Set maximumValue programmatically:
[a setMaximumValue: 1000.00];
/* INCORRECT: The thumb is still in the centre of the track: position "500.00":
1 --------------------------- () --------------------------- 1000
a.value == 50
|<---- It should be here (!)
*/
// Call setValue explicitly, to no avail:
[a setValue: 50.00];
/* INCORRECT: The thumb is still in the centre of the track: position "500.00":
1 --------------------------- () --------------------------- 1000
a.value == 50
|<---- It should be here (!)
*/ 我能够解决这个问题的唯一方法(在网上、在书中和实验中寻找了几个小时的解决方案)是对UISlider的值进行,这似乎会迫使UISlider重新绘制。我不喜欢它,但它是有效的:
[a setValue:a.value+1 animated:NO];
[a setValue:a.value-1 animated:NO];
/* (The thumb is now at position "50.00"):
1 -- () ---------------------------------------------------- 1000
a.value == 50
*/如果有人知道做这件事的更好的方法,我很想读一读。(-:
发布于 2011-03-31 17:30:41
如果要更改滑块拇指的值,则需要使用:
- (void)setValue:(float)value animated:(BOOL)animatedmaximumValue仅更改拇指所能表示的值的上限
https://stackoverflow.com/questions/5497447
复制相似问题