UISlider返回两个Touch Up Inside事件,为什么会这样? [英] UISlider returns two Touch Up Inside events, why does that happen?

查看:162
本文介绍了UISlider返回两个Touch Up Inside事件,为什么会这样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滑块,我用来设置一个浮点值。我将值更改连接到我的viewController中的方法。这部分工作正常。

I have a slider that I'm using to set a float value somewhere. I connect Value Changed to a method in my viewController. That part works fine.

我需要知道用户何时开始触摸控件,但不一定每一个滑块变化的瞬间(我收到值更改)。所以我将一个触摸内部事件连接到viewController中的另一个方法。

I need to know when the user starts touching the control but not necessarily every single instant that the slider changes (I receive the Value Changed events for that). So I connected a Touch Up Inside event to another method in the viewController.

问题是,当用户触摸时, 控件。 WTF?它不会以这种方式与 UIButtons 或像触摸等其他触摸事件。

The problem it, that method gets called twice when the user touches the UISlider control. WTF? It doesn't work that way with UIButtons or other touch events like Touch Down.

它,我想,但它似乎是一个错误的方式滑块控件处理触摸。是否有人知道为什么会发生?

I can work around it, I think, but it seems like a bug in the way the slider control handles touches. Does anybody know why it happens?

BTW :即使在

推荐答案

只要这样就不会打破未来的更新

Just so it doesn't break with future updates

[customSlider addTarget:self action:@selector(sliderDown:) forControlEvents:UIControlEventTouchDown];

[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];



- (void)sliderDown:(id)sender
{

    sliderused = NO;

}

- (void)sliderAction:(id)sender
{
    if(sliderused){
    return;
}

sliderused = YES;

//Your Code Here
}

这篇关于UISlider返回两个Touch Up Inside事件,为什么会这样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆