iphone - View 透明度和手势处理

标签 iphone objective-c ios uiview uigesturerecognizer

我目前正在尝试创建一个 View 来处理我的应用程序上可能发生的所有手势。

我希望这个 View 透明,以便将其他 View 放在下面,并且它们仍然会显示(我不想让它们成为处理 View 的 subview )

手势处理工作正常,直到我将 View 颜色设置为“clearColor”, View 才会消失。除非我粘贴 subview ,否则在这种情况下,手势仅在点击 subview 时才会发生。

因此我的问题是:我如何才能在透明 View 上发生手势事件?

最佳答案

尝试这样的事情。此代码将两个 subview 添加到主视图“bottomView”,它具有红色背景,然后“testView”,它是透明的,带有点击手势识别器,覆盖在“bottomView”之上。如果您在“testView”中点击,它会打印出 NSLog 消息。希望有帮助。

-(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");
}

关于iphone - View 透明度和手势处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11142176/

相关文章:

ios - 当 scrollView 设置 pagingEnabled 为 YES 时,点击 ScrollView 调用 `scrollViewWillBeginDecelerating`

ios - 在 iOS 上的 SQLite 中存储数据的最佳和最安全的方式

iphone - NSPredicate 检查数组中的所有项目

iphone - 在 COCOS2D 中启用 ARC 的问题

iphone - Xcode iPhone 应用程序 : How to print price float

ios - 无法在 Xcode 中可视化图像

Objective-C 相当于 Ruby 中的 string.unpack ('N' )

ios - RESTKit:两个端点 POST、PUT、DELETE

从 AppStore 外部安装的 iOS 应用程序

iphone - 仪器 vm 跟踪器脏