15

Is there any notification when frame or bounds of UIView changes? Whenever frame of a UIView changes, I need to calculate and set the frame of its custom subview so that it aspect fits in the superview.

NSView has the notification NSViewFrameDidChangeNotfication for the purpose. Why is this not there for UIView?

Andriy
  • 2,767
  • 2
  • 21
  • 29
spd
  • 2,114
  • 1
  • 29
  • 54
  • 3
    I've posted a solution on of how to do KVO on a UIViews frame. http://stackoverflow.com/questions/4874288/how-can-i-get-a-callback-by-kvo-on-a-uiviews-frame-property – hfossli Mar 02 '12 at 16:45
  • See my answer here how to achieve this using method swizzling and a UIView category: http://stackoverflow.com/a/39345728/480467 – Werner Altewischer Sep 06 '16 at 09:44

1 Answers1

13

There is no notification. You can subclass UIView to override layoutSubviews, to either do the layout directly or send the necessary notification.

Have you tried setting an appropriate autoresizingMask so the subview gets resized automatically?

Anomie
  • 92,546
  • 13
  • 126
  • 145