UISegmentedControl 委托/触摸事件

发布于 2024-08-17 20:58:11 字数 218 浏览 4 评论 0原文

我有一个 UISegmentedControl,它有六个段,我希望它们在值更改时调用一个方法,而且当每个段获得 UIControlEventTouchDragIn 时也调用一个方法,因为我希望 UILabel 在该人时显示其名称正在尝试选择其上的某些内容并将手指拖过控件,但即使当我拖入该内容时,分段控件也不会发送此调用。请帮忙。也许我需要在控件上创建 UIButtons,在拖入时调用方法,但在收到点击时调用值更改方法。

I have a UISegmentedControl that has six segments, I want them to call a method when the value changes, but also when each segment gets a UIControlEventTouchDragIn because I want a UILabel to show up with it's name when the person is trying to select something on it and drags their finger across the control, but the segmented control does not sen this call even when I drag into the thing. Please help. Maybe I need to create UIButtons over the control that call methods upon a drag in, but call the value changed method when they recieve a tap.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

独夜无伴 2024-08-24 20:58:11

也许我没有正确理解你的问题,但你不能只使用这个:

[segmentedControl addTarget:self 
         action:@selector(action:)  
         forControlEvents:UIControlEventValueChanged];

并用 UIControlEventTouchDragIn 替换 UIControlEventValueChanged 吗?然后在您的操作方法中执行任何需要执行的操作,例如更改 UILabel 的文本。

我有一个带有一堆单元格的 UITAbleView 和每个单元格中的 UISegmentedControll ,它对我来说工作得很好。

UISegmentedControl 的文档似乎无法在线获取,但您可以在 XCode 的 Organizer 中看到它,上面的代码是第一个示例。

Maybe I don't understand your question correctly but couldn't you just use this:

[segmentedControl addTarget:self 
         action:@selector(action:)  
         forControlEvents:UIControlEventValueChanged];

and just replace the UIControlEventValueChanged by UIControlEventTouchDragIn? Then in your action method do whatever needs to be done such as changing the text of a UILabel.

I have a UITAbleView with a bunch of cells and an UISegmentedControll in each cell and it works just fine for me.

The documentation for UISegmentedControl seems to be unavailable online but you can see it in XCode's Organiser and the code above is the first example.

小女人ら 2024-08-24 20:58:11

您可以仅对 UISegmentedControl 进行子类化并重写

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    return;
}

方法来管理触摸的拖动和位置。

由于无论如何您都无法判断拖动是在哪个部分,因此您最好通过触摸手动完成所有操作并使用这些功能跟踪它。

You could just subclass the UISegmentedControl and override

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    return;
}

method to manage the dragging and location of the touches.

Being that you wouldn't be able to tell which segment the drag is on anyway, it might be better for you to do everything manually with touch and track it using those functions.

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