UISlider值更改时会调用什么? [英] What gets called when a UISlider value changes?
问题描述
UISlider
的value
更改时是否调用方法?我希望能够基于UISliders
值来更新值,但仅当它更改时...
Does a method get called when a UISlider
's value
changes? I want to be able to update a value based on the UISliders
value, but only when it changes...
感谢您的帮助.
推荐答案
在IB中,您可以将IBAction
连接到Value Changed event
或在代码中添加UIControlEventValueChanged
的目标/操作.例如:
In IB, you can hook up an IBAction
to the Value Changed event
or in code add target/action for UIControlEventValueChanged
. For example:
[mySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
- (IBAction)sliderValueChanged:(UISlider *)sender {
NSLog(@"slider value = %f", sender.value);
}
请注意,如果要在用户为sliding
时进行值更改事件,则请确保还设置了slider
的continuous property
.另一方面,如果您不希望由于用户sliding
而触发事件,并且仅当用户完成滑动后才将其设置为NO(或在IB中取消选中)即可.
Note that if you want the value change events as the user is sliding
, then be sure that the slider
's continuous property
is also set. On the other hand, if you don't want the event to fire as the user is sliding
and only when they finish sliding, set continuous to NO (or uncheck in IB).
这篇关于UISlider值更改时会调用什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!