Search code examples
iosswiftcocoa-touchuiviewuiscrollview

How to detect when UIView size is changed in swift ios xcode?


I am trying some stuffs out with CATiledLayer inside UIScrollView.

Somehow, the size of UIView inside the UIScrollView gets changed to a large number. I need to find out exactly what is causing this resize.

Is there a way to detect when the size of UIView(either frame, bounds) or the contentSize of UIScrollView is resized?

I tried

override var frame: CGRect {
    didSet {
        println("frame changed");
    }
}

inside UIView subclass,

but it is only called once when the app starts, although the size of UIView is resized afterwards.


Solution

  • viewWillLayoutSubviews() and viewDidLayoutSubviews() will be called whenever the bounds change. In the view controller.