- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想实现 UIControl 的自定义子类。除了一个让我吐出 dentry 的致命问题外,它工作得很好。每当我使用 sendActionsForControlEvents: 发送操作消息时,它都会忽略包含 UIEvent。例如,如果我将它链接到具有以下签名的方法:
- (IBAction) controlTouched:(id)sender withEvent:(UIEvent *)event
...事件总是返回为 nil!问题似乎发生在 sendActionsForControlEvents 中:
现在,我需要我的 IBAction 能够确定触摸的位置。我通常通过从事件中提取触摸来做到这一点。一定有某种方法可以确保传递正确的事件吗?这是使用 UIControl 的一个非常基本的部分!
有人知道合法的解决方法吗?
最佳答案
我假设这是因为 sendActionsForControlEvents:
方法无法知道您的控制事件应该与哪个 UIEvent
(如果有)相关联。
您可以尝试单独发送所有操作(根据文档复制 sendActionsForControlEvents:
方法的作用),因此您可以专门将它们与 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];
}
}
关于iphone - UIControl:sendActionsForControlEvents 省略了 UIEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11382816/
UIControl 文档明确指出: When a user touches the control in a way that corresponds to one or more specified
我有一个简单的 UIButton 子类,我只想扩展按钮的触摸区域而不实际增加框架(这是因为我希望突出显示和选定的背景是原始框架的大小)。 这是我添加到 UIButton 子类中的内容: - (UIVi
我想实现 UIControl 的自定义子类。除了一个让我吐出 dentry 的致命问题外,它工作得很好。每当我使用 sendActionsForControlEvents: 发送操作消息时,它都会忽略
我有一个问题...正在寻找与 NSControl 的 sendActionsForControlEvents(来自 iOS UIControl)类似的方法? Mac 上有类似的东西吗?我需要获取有关更
我是一名优秀的程序员,十分优秀!