ios - 触摸开始 : withEvent: is not called when tapped on a UIButton

标签 ios objective-c uikit uitouch

我想实现的是列匹配类型功能。我在右栏上有三个按钮,在左栏上有三个按钮,上面有一些信息。我想通过拖动手指从右侧的一个按钮绘制路径到左侧的任何按钮。

我会使用 UIBezierPath 路径来绘制路径,为此绝对需要起点和终点。

现在的问题是如何通过点击按钮来触发 touchesBegantouchesMovedtouchesEnded 方法,以便我可以开始和结束点。

我正在考虑的另一个选择是用一个不可见的 UIView 覆盖所有按钮,并以某种方式检查这个覆盖 View 的触摸点是否位于任何按钮框架中。

顺便说一句,我也可以用简单的 UIImageView 替换这些按钮。我添加按钮只是为了获得接触点。

任何帮助。

最佳答案

创建 UIButton 的子类并添加这个...

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{  
    [super touchesBegan:touches withEvent:event];
    [self.nextResponder touchesBegan:touches withEvent:event]; 
}

这会让您在按钮内进行触摸。

关于ios - 触摸开始 : withEvent: is not called when tapped on a UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17966879/

相关文章:

ios - 关闭/弹出不同 Storyboard中的先前 View Controller

ios - 允许 UIScrollView 及其 subview 都响应触摸

ios - 如何在 WKWebView 中禁用 iOS 11 和 iOS 12 拖放?

iphone - Array 不从 plist 加载数据

ios - 尝试访问 PFUser 子类的动态属性时出错

iphone - View Controller 之间的自定义转换?

ios - AutoLayout + RTL + UILabel 文本对齐

iphone - 如果移动,UIImageView 将缩放而不是旋转,iOS

ios - 如何忽略多点触控序列中的某些 UITouch 点

ios - 考虑 iOS UI 初始化的推荐方法是什么?