Open churabou opened 6 years ago
中央がgradtionで
行って以外は黒
とにかくmask用のView
class RadialGradientLayer: CAShapeLayer {
required override init() {
super.init()
needsDisplayOnBoundsChange = true
fillRule = kCAFillRuleEvenOdd
fillColor = UIColor.black.cgColor
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
required override init(layer: Any) {
super.init(layer: layer)
}
public var colors = [UIColor.clear.cgColor, UIColor.black.cgColor]
override func draw(in ctx: CGContext) {
ctx.saveGState()
let colorSpace = CGColorSpaceCreateDeviceRGB()
let locations: [CGFloat] = [0, 1]
let gradient = CGGradient(colorsSpace: colorSpace,
colors: colors as CFArray,
locations: locations)
let center = CGPoint(x: bounds.width / 2.0, y: bounds.height / 2.0)
let radius = min(bounds.width / 2.0, bounds.height / 2.0)
ctx.drawRadialGradient(gradient!,
startCenter: center,
startRadius: 0.0,
endCenter: center,
endRadius: radius-250,
options: CGGradientDrawingOptions(rawValue: 0))
let path = UIBezierPath(rect: bounds)
path.append(UIBezierPath(arcCenter: center,
radius: radius-250,
startAngle: 0,
endAngle: 2*CGFloat.pi,
clockwise: true))
self.path = path.cgPath
}
}
あんま読んでない 結局ここっから
panでcenterで行けた。