iPhone:编程UISlider以定位点击位置 [英] iPhone:Programming UISlider to position at clicked location
本文介绍了iPhone:编程UISlider以定位点击位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将滑块设置为单击位置,并在iPhone编程中的UISlider上单击的位置获取滑块值。
我知道我们可以将滑块拖动到那个位置,但我不想这样做。你能告诉我如何将滑块设置为点击位置吗?这可能吗?
How to set the slider to clicked position and get the slider value on the clicked location on UISlider in iPhone programming. i know we can drag the slider to that position but i dont want to do it. Can you please tel me how to set the slider to clicked position? Is this possible to do?
推荐答案
以下是作为用户练习的部分:
Here is the part "left as a user exercise":
- (void) tapped: (UITapGestureRecognizer*) g {
UISlider* s = (UISlider*)g.view;
if (s.highlighted)
return; // tap on thumb, let slider deal with it
CGPoint pt = [g locationInView: s];
CGFloat percentage = pt.x / s.bounds.size.width;
CGFloat delta = percentage * (s.maximumValue - s.minimumValue);
CGFloat value = s.minimumValue + delta;
[s setValue:value animated:YES];
}
这篇关于iPhone:编程UISlider以定位点击位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文