简体   繁体   English

UISegmentedControl和UIPanGestureRecognizer?

[英]UISegmentedControl and UIPanGestureRecognizer?

I have a view with UIPanGestureRecognizer and UISegmentedControl . 我有一个与UIPanGestureRecognizerUISegmentedControl的视图。

Segmented control has different styles for highlighted and selected state. 对于突出显示和选定状态,分段控件具有不同的样式。

The problem is when I start pan gesture inside UISegmentedControl then it sometimes stays highlighted, but should be with selected style. 问题是当我在UISegmentedControl内开始平移手势时,它有时会保持突出显示,但应该使用选定的样式。

I tried to disable it when the touch is inside some area, but sometimes it still works. 当触摸在某个区域内时,我尝试禁用它,但是有时它仍然可以工作。

How to solve this issue? 如何解决这个问题? It is clearly seen when segmented control has for example different font colors for highlighted and selected states. 可以清楚地看到分段控件在突出显示和选定状态下具有不同的字体颜色。

I think you should use this method to prevent touch on specific controls:(for example:) 我认为您应该使用此方法来防止触摸特定控件:(例如:)

- (BOOL) gestureRecognizer: (UIGestureRecognizer *) gestureRecognizer
       shouldReceiveTouch:(UITouch *)touch
{
    if (touch.view == sliderButton)
    {
        return NO;
    }
    return YES;
}

You can replace 'sliderButton' with your segment control or whichever view you want. 您可以将“ sliderButton”替换为细分控件或所需的任何视图。

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

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