iOS 如何让超出父视图的部分响应事件

1.demo

奉上自己的demo

2. 不能点击的原因

由于找不到hittest view,所以没有可以响应的uiresponser对象,所以点击没有任何反应

3. 解决思想

覆写hittest方法让父视图可以找到这个视图就好

4. 代码演示
复制代码
- (UIView *)hitTest:(CGPoint)point withEvent:    (UIEvent *)event
{
  if (!self.isUserInteractionEnabled
      || self.isHidden
      || self.alpha <= 0.01)
  {
      return nil;
  }
  else
  {
      for (UIView *subView in [self.subviews reverseObjectEnumerator]) 
        {
          CGPoint convertedPoint = [subView convertPoint:point fromView:self];
          UIView *hitView = [subView hitTest:convertedPoint withEvent:event];
          if (hitView)
          {
              return hitView;
          }
      }
      return self;
  }
}
相关推荐
开开心心_Every2 天前
免费窗口置顶小工具:支持多窗口置顶操作
服务器·前端·学习·macos·edge·powerpoint·phpstorm
蜜汁小强2 天前
macOS 上卸载并重新安装HomeBrew
macos
新手村领路人2 天前
macOS 原生自带的缩放功能设置
macos
蒙小萌19932 天前
Performance and metrics
ios
小胖燕2 天前
macOS 系统本地部署 CVAT 进行数据标注
macos·cvat
海棠AI实验室2 天前
第 3 篇:服务编排与自启动——把 Mac 变成“稳定可运维”的家庭 AI 机房
运维·人工智能·macos
shughui2 天前
APP、Web、H5、iOS与Android的区别及关系
android·前端·ios
蜜汁小强2 天前
macOS 上管理不同版本的python
开发语言·python·macos
Edward.W2 天前
iOS 17+真机命令行操作对照表
macos·ios·cocoa
1telescope3 天前
MacBook 安装 nvm 管理 Node.js 多版本教程
macos·node.js