简体   繁体   English

隐藏视图时如何禁用 UISlider 交互?

[英]How to disable UISlider interaction when view is hidden?

Right now I have a UISlider that I set to hidden when a button is hit, but if I I'm interacting with the UISlider while I hit the button, the slider disappears but I'm still able to move the values of the slider.现在我有一个 UISlider,当按下按钮时我将它设置为隐藏,但是如果我在按下按钮时与 UISlider 交互,滑块会消失,但我仍然可以移动滑块的值。

I've tried to setUserIneractionEnabled = NO on the button press but that doesn't seem to do the trick.我试过在按下按钮时 setUserIneractionEnabled = NO ,但这似乎不起作用。

Any idea on how I should go about disabling this?关于我应该如何禁用它的任何想法?

EDIT * My code *编辑* 我的代码 *

- (void)didPressButton:(UIButton *)button
{
   if (!self.isShowingDetailView) //
   {
       self.showingDetailView = YES;
       self.valueSlider.hidden = YES;
       self.valueSlider.userInteractionEnabled = NO;
   }
   else
   {
       self.showingDetailView = NO;
       self.valueSlider.hidden = NO;
       self.valueSlider.userInteractionEnabled = YES;
   }

}

One way to fix is to set the exclusiveTouch property on the button and the slider.一种解决方法是在按钮和滑块上设置exclusiveTouch属性。 This way they can not receive touch simultaneously.这样他们就不能同时接收触摸。

It can be set either in Interface Builder or in code它可以在 Interface Builder 或代码中设置

If the value of the slider is important to you when the button is tapped then you should get and store the value when the button is tapped.如果点击按钮时滑块的值对您很重要,那么您应该在点击按钮时获取并存储该值。 Equally, you should set the slider value just before it is shown again.同样,您应该在再次显示之前设置滑块值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM