在这里,我想在按钮点击时触摸按钮操作事件 - B
当点击图像时(在图像的可见区域),点击手势方法将调用
但问题是图像位于按钮上并且覆盖了按钮的某些部分 我想在该覆盖部分上执行按钮操作事件 - A
我已经尝试过,但无法在覆盖部分上获得按钮操作:(
最佳答案
在该部分上放置一个透明按钮
更新
-(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/