0

I want to draw a shape hole in an @IBDesignable view. For this I need the size of a view, which is above in the view hierarchy. This view changes it's size by constraints.

How to retrieve the frame? May this is not possible at all, because the view we are depending on is drawn later? But it's frame size may be retrievable early?

<MainView>
   |  <View>
   |  |  <ViewWithShape>
   |  <ViewWeDependOn>

The shape is drawn in layoutSubviews:

   override func layoutSubviews() {
      super.layoutSubviews()
      if !(holeLayer != nil) {

         holeLayer = CAShapeLayer()
         layer.mask = holeLayer

         let rect = bounds // I need the frame HERE
         let path = UIBezierPath(quadrantHoleInsideRect: rect)

         holeLayer.path = path.CGPath
      }
   }
wider-spider
  • 465
  • 4
  • 12

1 Answers1

0

I put this question, because my first obvious solution would have been a outlet to the depending view from within the @IBDesignable view.

This gave me a crash at first, but it is now working as expected.

wider-spider
  • 465
  • 4
  • 12
  • But the ability of **life rendering is gone**: _error: IB Designables: Failed to render instance of xyView: The agent crashed_ – wider-spider Sep 02 '15 at 12:49