0
我有一個有一個的CALayer面具一個UIView:的CALayer containsPoint與面膜不工作
// 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的我只是想,如果用戶點擊一個動作happend在 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;
}
幫助,好嗎?