查看透明度和手势处理 [英] View transparency and Gesture handling
问题描述
我目前正在尝试创建一个视图,以处理应用程序中可能发生的所有手势.
I am currently trying to create a View that would handle all the Gesture that could happened on my application.
我希望此视图透明以便将其他视图放在下面,并且它们仍会显示(我不想将它们设为处理视图的子功能)
I would like this view transparent in order to put other view below and they would still display (I don't want to make them subbiews of the handling view)
从现在开始,在我将视图颜色设置为"clearColor"之前,手势处理效果都很好,这是视图消失的原因.除非我坚持使用子视图,否则在这种情况下,只有在点击子视图时才会发生手势.
The Gesture handling works fine until I set the view color on "clearColor" from then, it is has the view disappear. Unless I stick subviews, in this case the gesture are only happening when hitting on subviews.
因此,我的问题是:如何使Gesture事件在透明视图上发生?
My question hence is: How could I manage to have the Gesture event happening on a transparent view?
推荐答案
尝试类似的方法.此代码将两个子视图添加到主视图"bottomView,背景为红色",然后添加"testView",该视图为透明的,带有点击手势识别器的"bottomView"顶部的叠加层.如果仍然在"testView"中点击,打印出NSLog消息.希望对您有所帮助.
Try something like this. This code adds two subviews to the main view "bottomView which is has a red background and then "testView" which is transparent an overlay on top of "bottomView" with a tap gesture recognizer. If you tap anyway in the "testView" it will print out the NSLog message. I hope that helps.
-(void)viewDidLoad
{
[super viewDidLoad];
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[bottomView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:bottomView];
UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 150)];
[testView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:testView];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTap:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:testView];
[testView addGestureRecognizer:tapRecognizer];
}
-(void)handleTap:(UITapGestureRecognizer *)sender
{
NSLog(@"Tapped Subview");
}
这篇关于查看透明度和手势处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!