我使用UIBezierPath如下在tringular形狀掩蔽的UIView(240 * 240):限制UIPanGestureRecognizer在UIView的面膜
path = [UIBezierPath new];
[path moveToPoint:(CGPoint){0, 240}];
[path addLineToPoint:(CGPoint){120,0}];
[path addLineToPoint:(CGPoint){240,240}];
[path addLineToPoint:(CGPoint){0,240}];
[path closePath];
CAShapeLayer *mask = [CAShapeLayer new];
mask.frame = self.viewShape.bounds;
mask.path = path.CGPath;
self.viewShape.layer.mask = mask;
在上述圖像三角形區域是掩模。現在我有了可口可樂的形象,只能用三角形面具移動。所以,爲此,我已經應用UIPanGestureRecognizer到UIIMageView並按以下方式限制其框架。
- (void)handlePanGesture:(UIPanGestureRecognizer *)gestureRecognizer
{
CGPoint touchLocation = [gestureRecognizer locationInView:self.viewShape];
CGRect boundsRect;
BOOL isInside = [path containsPoint:CGPointMake(self.innerView.center.x, self.innerView.center.y)];
NSLog(@"value:%d",isInside);
if (isInside) {
NSLog(@"inside");
self.innerView.center = touchLocation;
}else{
NSLog(@"outside");
}
}
我上面如果條件執行成功,但是當控制進入其他條件,我不能拖回到面罩框架內我的ImageView。
所以,我的問題是當其他塊(外部)調用我應該能夠再次拖動imageView內的面具的框架。
我該如何做到這一點?
感謝您的回覆。我做了這樣的實現,但得到了相同的結果。 – iPhone