Objective c 顶部透明UIView检测触摸
我有一个用UISplitViewController构建的iPad项目:Objective c 顶部透明UIView检测触摸,objective-c,ios,touch,uigesturerecognizer,transparent,Objective C,Ios,Touch,Uigesturerecognizer,Transparent,我有一个用UISplitViewController构建的iPad项目: 根视图控制器 详细视图控制器 他们两个都在自己的类中使用手势识别器检测触摸 我想在所有类的顶部创建一个透明的ui视图,只检测对角滑动(从左下角到右上角) 因此,当检测到刷卡时,我将启动一个功能否则没有附加任何内容,触摸应在低层视图上传递 我尝试了以下两种解决方案: 在此顶部透明视图上添加一个手势识别器,但这将隐藏对较低层次视图的所有接触。(启用用户交互:当然是) 另一个解决方案是使init如下 -(id)initW
- 根视图控制器
- 详细视图控制器
- 在此顶部透明视图上添加一个手势识别器,但这将隐藏对较低层次视图的所有接触。(启用用户交互:当然是)李>
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.01]];
[self setUserInteractionEnabled:NO];
}
return self;
}
并尝试用
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
但是在这一点上,所有的触摸都没有被检测到
有人有一个好的解决方案吗?你能不能在
UISplitViewController的视图中添加一个手势识别器?我不会像你提到的那样创建一个透明的UIView。我将向UISplitViewController
的视图中添加一个uisweegesturecognizer
。该视图已包含所有子视图。您可以访问应用程序中的视图
委托:
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
// attach the swipe gesture to the view that embeds the rootView and the detailView
UISwipeGestureRecognizer* swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:splitViewController.view action:@selector(swipeUpdated:)];
您应该查看容器控制器
。您可以创建自己的SplitViewController
,并在检测刷卡的控制器顶部创建第三个视图。自定义容器控制器非常简单,给您带来了很大的灵活性。Tnx@tiguero快速回答。您是对的,但并非所有IOS版本都支持手势识别器。我发现正确的方法应该是对UIWindow进行子类化,并覆盖-(void)sendEvent:(UIEvent*)事件
和-(BOOL)pointInside:(CGPoint)pointwithEvent:(UIEvent*)事件
,这样我就可以调用/不调用[super sendEvent:event]
将事件传递或不传递到UIView层次结构中。你们觉得这个解决方案怎么样?