Created
June 28, 2019 14:28
-
-
Save sidepelican/61554dd1ff9cf02e9097037b1a964114 to your computer and use it in GitHub Desktop.
複数パスの図形を反転してマスク
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
view.backgroundColor = .white | |
} | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
present(PresentedViewController(), animated: true) | |
} | |
} | |
class PresentedViewController: UIViewController { | |
init() { | |
super.init(nibName: nil, bundle: nil) | |
modalPresentationStyle = .custom | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.backgroundColor = UIColor.darkGray.withAlphaComponent(0.5) | |
let image = UIGraphicsImageRenderer(bounds: view.bounds).image { context in | |
for angle: CGFloat in [0, -8, 12] { | |
let additional = UIBezierPath(roundedRect: .init(x: -60, y: -60, width: 120, height: 120), cornerRadius: 4) | |
additional.apply(CGAffineTransform(rotationAngle: angle)) | |
additional.apply(CGAffineTransform(translationX: 125 + 60, y: 350 + 60)) | |
additional.fill() | |
} | |
context.fill(view.bounds, blendMode: .sourceOut) | |
} | |
let maskLayer = CALayer() | |
maskLayer.contents = image.cgImage | |
maskLayer.frame = view.frame | |
view.layer.mask = maskLayer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment