- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 BooksEAGLView
并且它有 UIButton
用于接收触摸事件。然后我的增强现实覆盖的目的是将覆盖 View 添加到 BooksEAGLView
然后我的按钮没有接收到触摸事件。
如何获取两个 View 的触摸事件。
bookOverlayController = [[BooksOverlayViewController alloc]initWithDelegate:self];
// Create the EAGLView
eaglView = [[BooksEAGLView alloc] initWithFrame:viewFrame delegate:self appSession:vapp];
[eaglView addSubview:bookOverlayController.view];
[self setView:eaglView];
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return ([touch.view.superview isKindOfClass:[BooksEAGLView class]] || [touch.view.superview isKindOfClass:[TargetOverlayView class]]);
}
触摸事件:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
NSLog(@"hitTest:withEvent called :");
NSLog(@"Event: %@", event);
NSLog(@"Point: %@", NSStringFromCGPoint(point));
NSLog(@"Event Type: %d", event.type);
NSLog(@"Event SubType: %d", event.subtype);
NSLog(@"---");
return [super hitTest:point withEvent:event];
}
最佳答案
好的,我专门为你做了示例项目。这是我所做的:
在屏幕截图上,您可能会注意到 View 层次结构,它重复了您的概念。
这里在 CustomView.m 中覆盖了 hitTest:withEvent
:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (!self.clipsToBounds && !self.hidden && self.alpha > 0) {
for (UIView *subview in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [subview convertPoint:point fromView:self];
UIView *result = [subview hitTest:subPoint withEvent:event];
if (result != nil && [result isKindOfClass:[UIButton class]]) {
return result;
}
}
}
return [super hitTest:point withEvent:event];
}
该方法通过调用每个 subview 的pointInside:withEvent:
方法来遍历 View 层次结构,以确定哪个 subview 应该接收触摸事件。如果 pointInside:withEvent:
返回 YES,则类似地遍历 subview 的层次结构,直到找到包含指定点的最前面的 View 。如果 View 不包含该点,则忽略其 View 层次结构的分支。您很少需要自己调用此方法,但您可以覆盖它以从 subview 中隐藏触摸事件。此方法忽略隐藏的 View 对象、已禁用用户交互或 alpha 级别小于 0.01 的 View 对象。此方法在确定命中时不考虑 View 的内容。因此,即使指定的点位于该 View 内容的透明部分,仍然可以返回该 View 。
关于甜点:Sample Project
关于ios - 接收 subview 的触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22910347/
我在自定义表格单元格中长按时添加 subview ,但是当我滚动表格时, subview 消失。 p> 我应该怎么做,以便当我向后滚动时,该 subview 仍然显示/出现在该单元格上,或者换句话说,
如何遍历 UIView 的所有 subview ,以及它们的 subview 和它们的 subview ? 最佳答案 使用递归: // UIView+HierarchyLogging.h @inter
如果我有 contentView 和 2 个 subview 。我想根据subviewB居中subviewA subviewA 和 subviewB 有相同的父 View 。 这就是我现在正在做的,将
我想向 self.view 添加一个覆盖整个区域的 subview (如调光 View )。但在它下面,有一些 View 我不希望受到添加的 subview 的影响(我不希望这些 View 具有变暗的
我正在尝试向 UITabBar 添加 subview ,它应该位于其他 UITabBar subview 之后。 我在 UITabBarController 的子类中添加了这样的 subview :
图像描述了我必须将这种 subview 添加到我现有的单元格中,并且在多次单击“添加”图标时还要添加相同的 subview 。 我在添加 subview 时遇到困难。如果有人能为我提供处理此结构的正确
我添加了一个 subview ,如下所示: func showPlayerView2() { self.view.frame = CGRect(x: 0, y: 0, width: view.
我的问题是关于 UIView/CALayer: Transform triggers layoutSubviews in superview 据报道,来自苹果的 TSI 回复: Generally,
我试图为我的主视图创建一个辅助 View 。这个 subview 需要很小的高度,它需要适合另一个带有标签的大 UIView。 问题是当我使用 UIView addSubview 时,第三个 UIVi
我正在尝试淡出整个 View ,但只有一个特定的 subview , 这将强调 subview更清晰的外观。假设 self.view 有 5 textfields和 2 UIView如subviews
我确信我在这里错过了一些愚蠢的东西,但我有 mainView、subviewA 和 subviewB。我试图将 subviewB 添加到 subviewA 并将其锚定在 subviewA 内部,但是它
我有一个包含 3 个 subview 的 View ,分别称为 view A、view B、view C。 当我删除 subview 时,意味着我需要自动设置边距以进行调整。 当我删除 view A
我有两个加载的 subview 。一个是位于 View Controller 内部的选项卡栏,它很早就加载,第二个是按下选项卡栏项目时出现的 View 。 但是,当添加此 subview 时,它会加载
在 iOS 应用中,我在主视图中添加了一个 subview : [self.view addSubview:firstUIImageSubview]; 但是在 subview 类 firstUIIma
我正在制作一个球程序,您可以通过长按手势将球 UIView subview 添加到 super View 。点击 View 会将其从父 View 中移除。 添加所有 View 效果很好,重新添加 Vi
我使用以下代码在单击按钮时将日期选择器 View 添加到我的应用程序主视图。 - (IBAction)CalenderButton_Click:(id)sender { // code to add
我正在努力向 View 添加 subview 。进度变量在其 View Controller 的 viewDidLoad() 中设置。 progressView frame size 设置正确,只是添
这是我的代码 var button = [UIButton?](count:3, repeatedValue: UIButton()) for i in 0...2{
我有一个 UIViewController,里面有几个不同的 UIView subview 。当用户调用某个 Action 时,我手动更改每个的大小、比例和位置。我想更新其中一个 UILabel( s
我的屏幕有一个主视图模型。它由 2 个 subview 模型组成。 其中一个负责注册部分。其中一个处理登录部分。其中一个负责处理菜单部分(如果经过身份验证,可以显示哪些菜单项,以及“欢迎“用户名”类型
我是一名优秀的程序员,十分优秀!