Business
Jobs
  • About Us
  • Solutions
    • Candidates
      Highly qualified candidates in 48h.
    • Assessments
      500+ technical and psychological assessments, plus anti-fraud system.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Pay in 15+ LATAM countries without setting up a local entity.
  • Pricing
  • Jobs

0

321
Views
¿Cómo desenfocar el borde de la máscara para una NSImage?

Estoy tratando de desenfocar el borde de la máscara para una NSImage en Swift y no puedo entender cómo hacerlo. Se supone que la máscara se crea a partir de un CGMutablePath , para que se pueda cambiar mediante programación. Así es como se ve en este momento:Bordes afilados Así es como se supone que debe verse:Bordes borrosos

El código para crear la máscara con bordes afilados es el siguiente:

 class MyView: NSView { override func draw(_ dirtyRect: NSRect) { let bottomLayer = CALayer() bottomLayer.bounds = self.bounds bottomLayer.position = CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2) bottomLayer.contents = NSImage(named: "bottom.jpg") bottomLayer.contentsGravity = .resize self.layer?.addSublayer(bottomLayer) let path = CGMutablePath() path.move(to: CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2)) path.addCurve(to: CGPoint(x: 0.5*self.bounds.size.width, y: self.bounds.size.height), control1: CGPoint(x: 0.4*self.bounds.size.width, y: 0), control2: CGPoint(x: 0, y: self.bounds.size.height)) path.addCurve(to: CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2), control1: CGPoint(x: self.bounds.size.width, y: self.bounds.size.height), control2: CGPoint(x: 0.8*self.bounds.size.width, y: 0)) path.closeSubpath() let maskLayer = CAShapeLayer() maskLayer.path = path maskLayer.fillRule = .evenOdd maskLayer.borderWidth = 20 let topLayer = CALayer() topLayer.bounds = self.bounds topLayer.position = CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2) topLayer.contents = NSImage(named: "top.jpg") topLayer.contentsGravity = .resize topLayer.masksToBounds = true topLayer.mask = maskLayer self.layer?.addSublayer(topLayer) } }

Espero que haya una buena solución a esto :)

Federico

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Intente agregar CAGradientLayer en lugar de CAShapeLayer :

Fuente de muestra:

 class MyView: NSView { override func draw(_ dirtyRect: NSRect) { let bottomLayer = CALayer() bottomLayer.bounds = self.bounds bottomLayer.position = CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2) bottomLayer.contents = NSImage(named: "bottom") bottomLayer.contentsGravity = .resize self.layer?.addSublayer(bottomLayer) let path = CGMutablePath() path.move(to: CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2)) path.addCurve(to: CGPoint(x: 0.5*self.bounds.size.width, y: self.bounds.size.height), control1: CGPoint(x: 0.4*self.bounds.size.width, y: 0), control2: CGPoint(x: 0, y: self.bounds.size.height)) path.addCurve(to: CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2), control1: CGPoint(x: self.bounds.size.width, y: self.bounds.size.height), control2: CGPoint(x: 0.8*self.bounds.size.width, y: 0)) path.closeSubpath() let maskLayer = CAGradientLayer() maskLayer.shadowRadius = 4 maskLayer.shadowPath = path maskLayer.shadowOpacity = 1 maskLayer.shadowOffset = CGSize.zero maskLayer.shadowColor = NSColor.green.cgColor let topLayer = CALayer() topLayer.bounds = self.bounds topLayer.position = CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2) topLayer.contents = NSImage(named: "top") topLayer.contentsGravity = .resize topLayer.masksToBounds = true topLayer.mask = maskLayer self.layer?.addSublayer(topLayer) } }

Producción

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!