Is there a UIView resize event?

前端 未结 7 2140
难免孤独
难免孤独 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 03:47

    Pretty old but still a good question. In Apple's sample code, and in some of their private UIView subclasses, they override setBounds roughly like:

    -(void)setBounds:(CGRect)newBounds {
        BOOL const isResize = !CGSizeEqualToSize(newBounds.size, self.bounds.size);
        if (isResize) [self prepareToResizeTo:newBounds.size]; // probably saves 
        [super setBounds:newBounds];
        if (isResize) [self recoverFromResizing];
    }
    

    Overriding setFrame: is NOT a good idea. frame is derived from center, bounds, and transform, so iOS will not necessarily call setFrame:.

提交回复
热议问题