ios - 如何检测 UIView 大小何时在 swift ios xcode 中更改?

标签 ios swift cocoa-touch uiview uiscrollview

<分区>

我正在使用 UIScrollView 中的 CATiledLayer 尝试一些东西。

不知何故,UIScrollView 中的 UIView 的大小变大了。我需要查明到底是什么导致了这种调整。

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 子类中,

但它只在应用程序启动时调用一次,尽管 UIView 的大小随后会调整大小。

最佳答案

这里有一个答案:

https://stackoverflow.com/a/27590915/5160929

只需将其粘贴到方法体之外:

override var bounds: CGRect {
    didSet {
        // Do stuff here
    }
}

关于ios - 如何检测 UIView 大小何时在 swift ios xcode 中更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30616418/

相关文章:

ios - 如何在 Swift 中保存从 UIImagePickerController 中选取的图像?

ios - 在 StoryBoard 中显示图像而不是 UIBarButton 的文本

objective-c - 将委托(delegate)分配给 CALayer 的子层会抛出 EXC_BAD_ACCESS?

ios - 独立软件开发人员如何在他们没有的设备上测试应用程序

ios - UITableViewRowAction 标题作为图像图标而不是文本

ios - 如何在导航栏中添加自定义 View ?

Objective-C block 和变量范围

iOS swift 3 : does retain cycle happens in this case?

ios - 使用 Enum + Switch 进行错误处理时,如何显示不同的警报 View 功能?

ios - UINavigationController 背景颜色更改隐藏 iOS 中的后退按钮