如何检测swift ios xcode中何时更改UIView大小? [英] How to detect when UIView size is changed in swift ios xcode?
问题描述
我正在使用UIScrollView中的CATiledLayer尝试一些东西。
I am trying some stuffs out with CATiledLayer inside UIScrollView.
不知何故,UIScrollView中UIView的大小变为大数。我需要找出导致此调整大小的确切原因。
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.
有没有办法检测UIView的大小(帧,边界) )或者UIScrollView的contentSize是否已调整大小?
Is there a way to detect when the size of UIView(either frame, bounds) or the contentSize of UIScrollView is resized?
我试过
override var frame: CGRect {
didSet {
println("frame changed");
}
}
在UIView子类中,
inside UIView subclass,
但它仅在应用程序启动时调用一次,但之后会调整UIView的大小。
but it is only called once when the app starts, although the size of UIView is resized afterwards.
推荐答案
每当边界发生变化时,将调用
viewWillLayoutSubviews()
和 viewDidLayoutSubviews()
。在视图控制器中。
viewWillLayoutSubviews()
and viewDidLayoutSubviews()
will be called whenever the bounds change. In the view controller.
这篇关于如何检测swift ios xcode中何时更改UIView大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!