Autoresize UIPopoverController using autorun

I am trying to use autolayout to automatically resize my popover so that it matches its contents. I have a fixed width popover, but I rely on to calculate the height systemLayoutSizeFittingSize:, passing in my predefined width and zero height, for example. CGSizeMake (190, 0).

ContentController* controller = [ContentController new];
CGSize preferredSize = [controller.view systemLayoutSizeFittingSize:CGSizeMake(190, 0)];
controller.preferredContentSize = preferredSize;
UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:controller];
//popover presentation.

So far, so good, my current ContentController presentation hierarchy is similar to (setting in Interface Builder):

UILabel - multiline header (dynamically resized)
   |
UIImage with fixed width / height (static size)
   |
UILabel - multiline body (dynamically resized)

This way, I just include the header / body text, invoke systemLayoutSizeFittingSizeand return a valid size that matches the entire contents of the view.

Dynamic height label with short text

Dynamic height label with long text

The problem occurs when I try to put my body shortcut in a UIScrollView. (Both in IB and in code). Dynamic height is broken with scrollview

systemLayoutSizeFittingSize + . IB Pure Autolayout.

- , 0.
reset maxPreferredLayoutWidth , , , .

translatesAutoresizingMaskIntoConstraints , . / , scrollview - 1000, . .

IB:

Label setup

ScrollView with inner label setu

, - popover , .

_textContainerHeaderLabel.text = headerText;
_textContainerBodyTextLabel.text = bodyText;


[self.view setNeedsUpdateConstraints];
[self.view layoutSubviews];

, : , UIScrollViews?

+4
1

, . , , : ( >= 0) scrollview. , , ( - ). , , .

+3

Source: https://habr.com/ru/post/1535754/


All Articles