UIControl:sendActionsForControlEvents省略了UIEvent [英] UIControl: sendActionsForControlEvents omits UIEvent

查看:833
本文介绍了UIControl:sendActionsForControlEvents省略了UIEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现UIControl的自定义子类。除了一个致使我吐牙的致命问题外,它的工作非常精美。每当我使用sendActionsForControlEvents:发送动作消息时,它都会省略包含UIEvent。例如,如果我将其链接到具有以下签名的方法:

I want to implement a custom subclass of UIControl. It works beautifully except for one fatal problem that is making me spit teeth. Whenever I use sendActionsForControlEvents: to send an action message out, it omits to include a UIEvent. For example, if I link it to a method with the following signature:

- (IBAction) controlTouched:(id)sender withEvent:(UIEvent *)event

...事件总是以零返回!问题似乎发生在sendActionsForControlEvents中:

... the event always comes back as nil! The problem seems to occur within sendActionsForControlEvents:

现在,我需要我的IBAction才能确定触摸的位置。我通常是通过从事件中提取触摸来实现的。当然必须有某种方法来确保交付正确的事件?这是使用UIControl的一个非常基本的部分!

Now, I need my IBAction to be able to determine the location of the touch. I usually do so by extracting the touches from the event. Surely there must be some way to ensure that the correct event is delivered? It's a pretty fundamental part of using a UIControl!

任何人都知道合法的解决方法吗?

Anyone know a legal workaround?

推荐答案

我认为这是因为 sendActionsForControlEvents:方法无法知道哪个 UIEvent (如果有的话)你的控制事件应该与之相关联。

I would assume that this is because the sendActionsForControlEvents: method can't know which UIEvent (if any) your control event should be associated with.

你可以尝试单独发送所有动作(复制 sendActionsForControlEvents:方法,根据文档),所以你可以专门将它们与 UIEvent 相关联:

You could try to send all the actions separately (replicating what the sendActionsForControlEvents: method does, according to the documentation), so you can specifically associate them with a UIEvent:

UIEvent *event = ...;
UIControlEvents controlEvent = ...;

for (id target in [self allTargets]) {
    NSArray *actions = [self actionsForTarget:target forControlEvent:controlEvent];
    for (NSString *action in actions) {
        [self sendAction:NSSelectorFromString(action) to:target forEvent:event];
    }
}

这篇关于UIControl:sendActionsForControlEvents省略了UIEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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