Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- imageView.layer.mask = ({
- () -> CAShapeLayer in
- class Anon: CAShapeLayer {
- override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
- switch (keyPath, change?[.oldKey], change?[.newKey]) {
- case ("superlayer", let old, _) where old != nil:
- (old as? NSObject)?.removeObserver(self, forKeyPath: "bounds")
- case ("superlayer", _, let new) where new != nil:
- (new as? NSObject)?.addObserver(self, forKeyPath: "bounds", options: [.new], context: nil)
- case ("bounds", _, _), ("superlayer", _, _):
- let r = self.superlayer!.bounds.height / 8.5
- self.frame = self.superlayer!.bounds
- self.path = UIBezierPath(roundedRect: self.superlayer!.bounds, byRoundingCorners: [.topRight, .bottomRight], cornerRadii: CGSize(width: r, height: r)).cgPath
- default: break
- }
- }
- }
- return Anon()
- })()
- imageView.layer.mask?.observeValue(forKeyPath: "superlayer", of: nil, change: [.newKey: imageView.layer as Any], context: nil)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement