我有一个带有 CALayer 掩码的 UIView:
// Getting the right mask image
UIImage *myimage = [UIImage imageNamed:[NSString stringWithFormat:@"img%d", imageIndex]];
// Scaling image to fit UIView
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0);
[myimage drawInRect:self.bounds];
myimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.layer setMasksToBounds:YES];
// Setting mask
UIImage *_maskingImage = myimage;
CALayer *_maskingLayer = [CALayer layer];
_maskingLayer.frame = self.bounds;
[_maskingLayer setContents:(id)[_maskingImage CGImage]];
[self.layer setMask:_maskingLayer];
当用户稍后短按 (UILongPressGestureRecognizer *) UIView 时,我只想在用户点击 UIView 图层蒙版时发生一个动作(现在 containsPoint 总是返回 YES):
// Object is a UIView
CALayer *layer = [Object.layer mask];
// Sender is a UILongPressGestureRecognizer
location2 = [sender locationInView:Object];
// The position is correct
NSLog(@"%@", NSStringFromCGPoint(location2));
if ([layer containsPoint:location2]){
NSLog(@"HELLO WORLD!");
return;
}
请帮忙?