Dans mon application, j'ai fait un UIView
voir en sous-classe UIView simple. Cependant, si j'essaye de faire la même chose en utilisant UIVisualEffectView
, je ne suis pas capable de le faire.Comment faire une coupe transparente sur UIVisualEffectView?
Voici ce que je suis capable de faire en utilisant la normale UIView
:
Lorsque j'utilise le UIVisualEffectView
à la place du vert UIView
, je ne vois pas le voir à travers UIView, bien que voir à travers UIView
est ajouté au UIVisualEffectView
en tant que subview
.
code:
- (void)drawRect:(CGRect)rect { //this is same for the UIVIew and for the UIVisualEffectView
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
// Clear any existing drawing on this view
// Remove this if the hole never changes on redraws of the UIView
CGContextClearRect(context, self.bounds);
// Create a path around the entire view
UIBezierPath *clipPath = [UIBezierPath bezierPathWithRect:self.bounds];
// Your transparent window. This is for reference, but set this either as a property of the class or some other way
CGRect transparentFrame;
// Add the transparent window
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:transparentFrame cornerRadius:5.0f];
[clipPath appendPath:path];
// NOTE: If you want to add more holes, simply create another UIBezierPath and call [clipPath appendPath:anotherPath];
// This sets the algorithm used to determine what gets filled and what doesn't
clipPath.usesEvenOddFillRule = YES;
// Add the clipping to the graphics context
[clipPath addClip];
// set your color
UIColor *tintColor = [UIColor greenColor];
// (optional) set transparency alpha
CGContextSetAlpha(context, 0.7f);
// tell the color to be a fill color
[tintColor setFill];
// fill the path
[clipPath fill];
}
Question: Pourquoi cela n'a pas avec UIVisualEffectView
?
Salut Teja, Pourriez-vous être en mesure d'atteindre la fonctionnalité que vous avez mentionné dans ce post. Si oui, pouvez-vous m'aider ou suggérer quelques modifications pour le code donné dans le message suivant. http://stackoverflow.com/questions/39165751/circle-masking-for-image-cropping-in-ios?noredirect=1#comment65676404_39165751 –
@sree_iphonedev fera une fois que je suis en face de l'ordinateur! –
L'avez-vous résolu finalement? –