Ich arbeite mit Xcode 8 und Swift 2.3
von this nice post Ab Hinzufügen und my own question kann ich diese zwei unterschiedliche Effekte bekommen, aber ich kann nicht „join“ es.einen Kreis unscharfe Maskenschicht auf UIView
erste (Unschärfe):
internal extension UIView {
/**
Add and display on current view a blur effect.
*/
internal func addBlurEffect(style style: UIBlurEffectStyle = .ExtraLight, atPosition position: Int = -1) -> UIView {
// Blur Effect
let blurEffectView = self.createBlurEffect(style: style)
if position >= 0 {
self.insertSubview(blurEffectView, atIndex: position)
} else {
self.addSubview(blurEffectView)
}
return blurEffectView
}
internal func createBlurEffect(style style: UIBlurEffectStyle = .ExtraLight) -> UIView {
let blurEffect = UIBlurEffect(style: style)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.bounds
blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
return blurEffectView
}
}
zweite (radiale Gradienten):
public class BlurFilterMask: CAShapeLayer {
// MARK: - Public properties -
public var origin: CGPoint = CGPointZero
public var diameter: CGFloat = 0.0
public var gradientWidth: CGFloat = 200.0
public var gradientColorOpacity: CGFloat = 0.5
// MARK: - Layout -
override public func drawInContext(ctx: CGContext) {
let clearRegionRadius = self.diameter * 0.5
let blurRegionRadius = clearRegionRadius + self.gradientWidth
let baseColorSpace = CGColorSpaceCreateDeviceRGB()
let colours: [CGFloat] = [0.0, 0.0, 0.0, 0.0, // Clear region
0.0, 0.0, 0.0, self.gradientColorOpacity] // blur region color
let colourLocations: [CGFloat] = [0.0, 0.4]
let gradient = CGGradientCreateWithColorComponents (baseColorSpace, colours, colourLocations, 2)
CGContextDrawRadialGradient(ctx, gradient!, self.origin, clearRegionRadius, self.origin, blurRegionRadius, .DrawsAfterEndLocation)
}
}
würde geschätzt Irgendwelche Tipps!
hast du nicht kürzlich eine ähnliche Frage gestellt? http://stackoverflow.com/questions/40256942/draw-hole-on-uiblureffect/40401855#40401855 –
Ähnlich kann ich nicht einen radialen Gradienten auf das Loch anwenden ... Ich habe versucht mit allen möglichen Kombinationen! –