如何向 UISliderControl 添加增量点击调整?

发布于 2024-11-06 12:41:33 字数 277 浏览 4 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惜醉颜 2024-11-13 12:41:33

您正在寻找的内容称为 <代码>UITapGestureRecognizer。在控制器的 viewDidLoad 方法中,添加以下代码:

    UITapGestureRecognizer *tap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapSlider:)];
    [mySliderControl addGestureRecognizer:tap];
    [tap release];

...然后,向控制器添加一个方法:

- (void)didTapSlider:(UITapGestureRecognizer *)tap

当用户点击 UISlider 时,会调用 didTapSlider: 方法,并且 tap 的内容(特别是 locationOfTouch:inView:)会告诉你细节。从那里您可以根据需要增加或减少滑块的值。

What you're looking for is called a UITapGestureRecognizer. In the viewDidLoad method of your controller, add this code:

    UITapGestureRecognizer *tap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapSlider:)];
    [mySliderControl addGestureRecognizer:tap];
    [tap release];

...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 of tap (in particular locationOfTouch:inView:) will tell you the details. From there you can increment or decrement the slider's value as needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文