Advertisement
Guest User

Untitled

a guest
Jul 12th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.51 KB | None | 0 0
  1.                 imageView.layer.mask = ({
  2.                     () -> CAShapeLayer in
  3.                     class Anon: CAShapeLayer {
  4.                         override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
  5.                             switch (keyPath, change?[.oldKey], change?[.newKey]) {
  6.                                 case ("superlayer", let old, _) where old != nil:
  7.                                     (old as? NSObject)?.removeObserver(self, forKeyPath: "bounds")
  8.                                 case ("superlayer", _, let new) where new != nil:
  9.                                     (new as? NSObject)?.addObserver(self, forKeyPath: "bounds", options: [.new], context: nil)
  10.                                 case ("bounds", _, _), ("superlayer", _, _):
  11.                                     let r = self.superlayer!.bounds.height / 8.5
  12.                                     self.frame = self.superlayer!.bounds
  13.                                     self.path = UIBezierPath(roundedRect: self.superlayer!.bounds, byRoundingCorners: [.topRight, .bottomRight], cornerRadii: CGSize(width: r, height: r)).cgPath
  14.                                 default: break
  15.                             }
  16.                         }
  17.                     }
  18.                     return Anon()
  19.                 })()
  20.                 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