如何向 UISliderControl 添加增量点击调整?
在 iPhone 应用程序中,我希望允许用户点击 UISliderControl 将滑块减少固定量。我该怎么做呢?
澄清: 用户将使用滑块来调整目标数值,其粒度对于 UISliderControl 单独设置来说太细了。例如,值的范围可以从 0 到 1000,但由于像素限制(即 0、3、6、9),滑块可能只能覆盖该值的 1/3。在此示例中,我想向滑块添加点击手势,该手势会将目标值减少 1。因此,如果滑块的粒度仅变为 0、3、6、9,而用户需要 7,则他可以移动将滑块移动到 9,然后点击滑块两次。
谢谢
In an iphone app, I would like to allow the user to tap a UISliderControl to decrement the slider by a fixed amount. How would I go about doing this?
Clarification:
The user will be using sliders to adjust target numeric values at granularities that are too fine for the UISliderControl alone to set. So for example, a value could range from 0 to 1000, but the slider may only be able to cover 1/3rd of the values due to pixel constraints (ie, 0, 3, 6, 9). In this example, I would like to add a tap gesture to the slider that would decrement the target value by 1. So if the granularity of the slider only goes to 0, 3, 6, 9 and the user needs 7, he could move the slider to 9 and tap the slider twice.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的内容称为 <代码>UITapGestureRecognizer。在控制器的
viewDidLoad
方法中,添加以下代码:...然后,向控制器添加一个方法:
- (void)didTapSlider:(UITapGestureRecognizer *)tap
当用户点击 UISlider 时,会调用
didTapSlider:
方法,并且tap
的内容(特别是locationOfTouch:inView:
)会告诉你细节。从那里您可以根据需要增加或减少滑块的值。What you're looking for is called a
UITapGestureRecognizer
. In theviewDidLoad
method of your controller, add this code:...then, add a method to your controller:
- (void)didTapSlider:(UITapGestureRecognizer *)tap
The
didTapSlider:
method will be called when the user taps the UISlider, and the contents oftap
(in particularlocationOfTouch:inView:
) will tell you the details. From there you can increment or decrement the slider's value as needed.