How to make subview resize automatically using my supervisor?

I have a view that contains one subrecord; This subtask itself contains another subtask, which should be slightly smaller than its supervisor.

I create the first full-size subview and then reduce it to a very small size on the screen. When a subview is connected, I animate it from its small size to full screen.

The problem is that my second subtitle never changes size during this animation - it always displays full size and overflows the boundaries of its supervisor.

Is there an easy way to get subview to keep the size proportional since its size changes?

+7
source share
3 answers

you can add software dependent behavior

Objective-c

subview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

Swift 3.x

 subview.autoresizingMask = [.flexibleWidth, .flexibleHeight] 

Swift 2.x

 subview.autoresizingMask = [.flexibleWidth, .flexibleHeight] 

In Interface-Builder, go to tab 3 and click on the arrows in the middle, D

Another workaround is to implement the setFrame method and always adapt it to the size of the supervisor (not specified by frame.size). Remember to indicate the source you need.

 - (void) setFrame:(CGRect)frame { CGRect rect = self.superview.frame; rect.origin.x = 0; rect.origin.y = 0; [super setFrame:rect]; } 
+25
source

it does the trick for me

 subview.frame = subview.superview.bounds; 
+5
source

If you use only the [.flexibleWidth, .flexibleHeight] mask to mask your autoresist, your subview will not be proportionally resized. Correct answer:

 autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleLeftMargin, .flexibleBottomMargin, .flexibleRightMargin] 
+1
source

All Articles