iphone - 如何在iOS上触摸图像透明部分的 ImageView 后面?

标签 iphone ios touch user-interaction image-masking

在这里,我想在按钮点击时触摸按钮操作事件 - B

当点击图像时(在图像的可见区域),点击手势方法将调用

但问题是图像位于按钮上并且覆盖了按钮的某些部分 我想在该覆盖部分上执行按钮操作事件 - A

我已经尝试过,但无法在覆盖部分上获得按钮操作:(

Image Masking

最佳答案

在该部分上放置一个透明按钮

更新

 -(void)singleTapImageview:(UITapGestureRecognizer *)gesture
 {
    NSLog(@"single-tap");
    CGPoint touchLocation = [gesture locationInView:self.imageViewParent];
    float x = touchLocation.x;
    float y = touchLocation.y;

    //Using gesture recogniser you can get the current position of touch

    UIImage* image = imageViewParent.image;
    CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage));
    UInt8 *pixels = (UInt8 *)CFDataGetBytePtr(data);

    UIGraphicsBeginImageContext(image.size);
    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 1);
    CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [UIColor redColor].CGColor);
    int index = ((x + (y * (int)image.size.width)) * 4) + 3;
    CGFloat alpha = pixels[index];
    if (alpha == 0)
    {
        // call button acton
    }

}

关于iphone - 如何在iOS上触摸图像透明部分的 ImageView 后面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14687297/

相关文章:

ios - 当我添加到基本 SDK 中时,在 Xcode 8 中找不到 SDK,它会显示此信息

ios - UIPageViewController/TextKit 在分页上重排文本

ios - 如何将UICollectionViewCell中的图像显示到另一个UIImageView? ( swift 3)

ios - touchesBegan :withEvent: on UIView in UITableViewCell called with noticable delay

iphone - iOS 开发 : When making a POST request, 如果我在 URL 中包含参数真的很重要吗?

ios - rightBarButtonItem 添加 segue

iphone - UIImagePickerController 不会显示相机,只有相机胶卷

ios - 使用带有自定义参数的 Malcom API 发送推送通知

android - 由于 (x, y) 处没有可触摸窗口而丢弃事件

jquery - 使用jquery在touchmove上滚动事件