clip de masquage uiview avec CAShapeLayer et UIBezierPath
J'ai un problème de détourage d'une vue à l'aide de CAShapeLayer-UIBezierPath , je veux clip le contenu, mais que je finis par avoir un accident vasculaire cérébral (frame) avec qui UIBezierPath , C'est mon code
UIBezierPath *path2Path = [UIBezierPath bezierPath];
[path2Path moveToPoint:CGPointMake(206.745, 0)];
[path2Path addLineToPoint:CGPointMake(206.745, 97.613)];
[path2Path addLineToPoint:CGPointMake(0, 97.613)];
[path2Path addLineToPoint:CGPointMake(0, 0)];
[path2Path addLineToPoint:CGPointMake(87.28, 0)];
[path2Path addCurveToPoint:CGPointMake(103.808, 12.118) controlPoint1:CGPointMake(87.28, 0) controlPoint2:CGPointMake(86.555, 12.118)];
[path2Path addCurveToPoint:CGPointMake(119.466, 0) controlPoint1:CGPointMake(121.061, 12.118) controlPoint2:CGPointMake(119.466, 0)];
[path2Path addLineToPoint:CGPointMake(206.745, 0)];
[path2Path closePath];
[path2Path addClip];
CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame=MYVIEW.bounds;
pathLayer.path = path2Path.CGPath;
pathLayer.strokeColor = [[UIColor blackColor] CGColor];
pathLayer.fillColor = [[UIColor clearColor] CGColor];
pathLayer.fillRule=kCAFillRuleEvenOdd;
[MYVIEW.layer setMask:pathLayer];
[MYVIEW.layer setMasksToBounds:YES];
MYVIEW.backgroundColor=[UIColor greenColor];
Le résultat de ce code est juste un vert course ligne ,les limites est vide ,
comme ceci
http://i.stack.imgur.com/aehdo.png
Cependant , je tiens à apporter les limites vert , coupé par ce contour
Vous voulez afficher la seule partie de l'image à l'intérieur de tracé de bézier. Droit?
oui exactement . @RajeshMaurya
Puis-je savoir? lorsque vous écrivez le code? Dans le Viewcontroller ou créé sous-classe UIView.
Avez-vous ajouté une image dans MAVUE?
double possible de l'Utilisation Tracé de Bézier comme Masque d'Écrêtage
oui exactement . @RajeshMaurya
Puis-je savoir? lorsque vous écrivez le code? Dans le Viewcontroller ou créé sous-classe UIView.
Avez-vous ajouté une image dans MAVUE?
double possible de l'Utilisation Tracé de Bézier comme Masque d'Écrêtage
OriginalL'auteur Aproram | 2015-06-19
Vous devez vous connecter pour publier un commentaire.
comme rob mayoff dit Vous pouvez le faire facilement en réglant votre vue de la couche de masque à un CAShapeLayer.
Dans Swift
OriginalL'auteur Harvant S. Choudhary
Merci pour les réponses les gars.
Dans le cas où quelqu'un ne peut pas trouver de réponse sur la ALORS pour cette question pendant des heures, comme je viens de le faire, j'ai assemblé un travail essentiel dans Swift 2.2 pour le masquage/écrêtage UIView avec CGRect/UIBezierPath:
https://gist.github.com/Flar49/7e977e81f1d2827f5fcd5c6c6a3c3d94
Utilisation:
Espère qu'il va sauver quelqu'un certain moment dans le futur 🙂
OriginalL'auteur Flar