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;
  }
}
相关推荐
如此风景14 小时前
iOS SwiftUI开发所有修饰符使用详解
ios
mumuWorld14 小时前
KSCrash 实现机制深度分析
ios·源码阅读
AskHarries14 小时前
Google 登录问题排查指南
flutter·ios·app
崽崽长肉肉15 小时前
Swift中的知识点总结
ios·swift
2501_9160074716 小时前
苹果手机iOS应用管理全指南与隐藏功能详解
android·ios·智能手机·小程序·uni-app·iphone·webview
2501_9151063219 小时前
全面理解 iOS 帧率,构建从渲染到系统行为的多工具协同流畅度分析体系
android·ios·小程序·https·uni-app·iphone·webview
TouchWorld21 小时前
iOS逆向-哔哩哔哩增加3倍速(1)-最大播放速度
ios·逆向
RollingPin21 小时前
React Native与Flutter的对比
android·flutter·react native·ios·js·移动端·跨平台开发
2501_9160088921 小时前
iOS 能耗检测的工程化方法,构建多工具协同的电量分析与性能能效体系
android·ios·小程序·https·uni-app·iphone·webview
long_run21 小时前
Objective-C 类与对象详细入门
ios