2015-08-30 10 views
9

Sto provando a creare un tipo di vista trasparente su UIVisualEffectView. Stavo seguendo la soluzione data here. Ho allegato il mio codice di esempio che ho lavorato su here. Sto provando a creare una vista trasparente la cui cornice è presa dalla vista immagine dietro la vista sfocata. Qualcuno potrebbe dirmi cos'è che sto facendo di sbagliato qui?Creazione di un foro trasparente sulla vista UIVisualEffect

risposta

11

È possibile utilizzare uno UIBezierPath per creare la maschera desiderata.

blurView.layer.mask = ({ 
    CGRect roundedRect = self.bounds; 
    roundedRect.origin.x = roundedRect.size.width/4.0f; 
    roundedRect.origin.y = roundedRect.size.height/4.0f; 
    roundedRect.size.width /= 2.0f; 
    roundedRect.size.height /= 2.0f; 

    CGFloat cornerRadius = roundedRect.size.height/2.0f; 

    UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds]; 
    UIBezierPath *croppedPath = [UIBezierPath bezierPathWithRoundedRect:roundedRect cornerRadius:cornerRadius]; 
    [path appendPath:croppedPath]; 
    [path setUsesEvenOddFillRule:YES]; 

    CAShapeLayer *mask = [CAShapeLayer layer]; 
    mask.path = path.CGPath; 
    mask.fillRule = kCAFillRuleEvenOdd; 
    mask; 
}); 
+0

Incredibile! Funziona come un fascino! – SaltyNuts

+0

Thankuuuuuuuuu;) – ishhhh

+0

Come impostare quella vista chiara arrotondata solo cliccabile significa abilitare l'interazione dell'utente solo su quella parte @ cnotethegr8 –

Problemi correlati