Is there a UIView resize event?

前端 未结 7 2115
难免孤独
难免孤独 2020-11-28 03:29

I have a view that has rows and columns of imageviews in it.

If this view is resized, I need to rearrange the imageviews positions.

This view is a subview of

相关标签:
7条回答
  • 2020-11-28 04:06

    In a UIView subclass, property observers can be used:

    override var bounds: CGRect {
        didSet {
            // ...
        }
    }
    

    Without subclassing, key-value observation with smart key-paths will do:

    var boundsObservation: NSKeyValueObservation?
    
    func beginObservingBounds() {
        boundsObservation = observe(\.bounds) { capturedSelf, _ in
            // ...
        }
    }
    
    0 讨论(0)
提交回复
热议问题