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;
  }
}
相关推荐
2501_916007478 小时前
iOS 自动化上架的工具组合,在多平台环境中实现稳定发布
android·运维·ios·小程序·uni-app·自动化·iphone
TO_ZRG8 小时前
iOS 符号表文件概要
macos·ios·cocoa
默默在路上8 小时前
M芯片使用VMware Fusion安装CentOS Stream 9教程
linux·macos·centos
TheNextByte18 小时前
如何在Mac上收发Android信息 [2026 指南]
android·macos
耘田8 小时前
 macOS Launch Agent 定时任务实践指南
java·开发语言·macos
不爱吃糖的程序媛8 小时前
macOS 系统本地安装 openJiuwen 完整指南
macos
William.csj8 小时前
Mac——一款支持跨平台的与服务器之间的远程传输工具 FileZilla
macos·filezilla
shankss1 天前
GetX 状态管理详解
android·flutter·ios
Nightmare0041 天前
Mac打开终端
macos
shankss1 天前
Flutter 项目启动全流程详解
android·flutter·ios