新建一个UIImageView的子类。
并重写 :
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{ unsigned char pixel[1] = {0}; CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 1, NULL, kCGImageAlphaOnly); UIGraphicsPushContext(context); [self.image drawAtPoint:CGPointMake(-point.x, -point.y)]; UIGraphicsPopContext(); CGContextRelease(context); CGFloat alpha = pixel[0]/255.0f; NSLog(@"------%.2f---",alpha); BOOL transparent = alpha < 0.01f; return !transparent; }
这样的话,这个图片的像素小于0.01的地方就不会响应手势,像素大于0.01的地方才会响应手势。
时间: 2024-10-13 14:32:14