objective-c - 交互式触摸显示屏

标签 objective-c user-interface user-experience

我希望拦截父 UIView 上的所有触摸事件并显示用户触摸的位置,但仍然将这些触摸事件冒泡到 subview ,即 UIButtons、UITableViewCell 等,以便这些 subview 通过默认方式进行交互。

我使用基本委托(delegate)方法在 UIView 上以交互方式显示触摸事件没有问题:

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

    -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
         [super touchesEnded:touches withEvent:event];
    }

此时我的问题是,当 UIView 包含其他交互式 subview (例如 UIButtons)时,将这些事件冒泡到下一个响应者。 TouchsBegan:点击按钮时永远不会在父 View 上触发,因此我无法在点击按钮时向用户显示“漂亮”的内容。

除了为 UIButton、UITableViewCell 创建类别之外,还有更好的方法吗?谢谢

这是我希望在用户触摸屏幕时执行的操作的示例...(请注意用户触摸按钮时的白色圆圈): https://m1.behance.net/rendition/modules/154366385/disp/9532a948c71e28ffda2219600c05ffd9.gif

最佳答案

您可以通过创建 UIView 的子类来做到这一点。 View 应该位于 View 层次结构的顶部,并且其大小应该充满屏幕。

所有触摸事件都将发送到此 View 。如果在pointInside:widthEvent:方法中返回NO,则触摸事件将被发送到下层对象。

@implementation MyView

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    // show bubble here
    return NO; // send touch events to lower layer objects. 
}

关于objective-c - 交互式触摸显示屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28893859/

相关文章:

ios - 在 afnetworking 中为授权 token 设置请求 header

ios - 为什么在打印核心位置返回到控制台的位置时出现无限循环?

usability - 您应该向用户体验 (ux) 开发人员/设计师询问哪些面试问题

css - 使用 CSS 在设计布局上制作拱形曲线的问题

objective-c - 解析 Graphviz 的 Dot 语言

ios - VoIP 限制 rendercallback 中的帧数

ios - 通过不同容器 View 中的 UI 按钮更改容器 View 内容

c++ - GUI系统开发资源?

java - SWT:获取即将从文本小部件中删除的字符数

javascript - 类似github的浏览器前进/后退滑动页面效果