在这里,我希望按下按钮点击按钮动作事件 - B
当点击图像时(在图像的可见区域上),点击手势方法将调用
但问题是图像在按钮上,它覆盖了按钮的某些部分 我想在该覆盖部分执行按钮操作事件 - A
我已经尝试但无法在被遮盖的部分上获取按钮操作:(
任何人都可以帮我这个吗?
答案 0 :(得分:3)
在该部分上方放置一个透明按钮
<强>更新强>
-(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
}
}
答案 1 :(得分:0)
您可以添加一个新的透明按钮,该按钮与图像部分和现有按钮重叠,具有框架
CGRectMake(button.frame.origin.x, button.frame.origin.y, button.frame.size.width, button.frame.size.height);
答案 2 :(得分:0)
避免以这种方式将按钮与图像重叠。看起来很糟糕。
对于更长期的解决方案,我建议与UX设计师和图形艺术家交朋友。如果你很幸运,甚至可能是同一个人。
答案 3 :(得分:0)
您可以通过为重叠按钮编写hittest函数来解决问题。
在最新的测试中,你必须通过检查坐标来确定击中了哪个按钮。