0
votes

I have a view which contains a scrollview, a containerview and 3 subviews (topview, textview and bottomview). See the view's hierachy below. The height of the textview is defined based on its content. I defined a dynamic constraint for its height and I change it in viewDidLayoutSubviews. The size of the textview is correct but the problem is that my scrollview is not scrolling. What I am doing wrong? Perhaps I need to add/modify some of the other constraints?

enter image description here

-(void)viewDidLayoutSubviews
{
    NSAttributedString * string = [[NSAttributedString alloc] initWithString:self.game.description];
    CGFloat heightTV = [self textViewHeightForAttributedText:string andWidth:260];
    self.dynamicTVHeight.constant = heightTV;
    [self.view layoutIfNeeded];
}

- (CGFloat)textViewHeightForAttributedText:(NSAttributedString *)text andWidth:(CGFloat)width
{
    UITextView *textView = [[UITextView alloc] init];
    [textView setAttributedText:text];
    CGSize size = [textView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}
1

1 Answers

1
votes

The UIScrollView scroll only if it has contentSize bigger than bounds. Content size of UIScrollView can be set automatically by calculating frames of subviews (calculated from constraints) or manually in code (usually in viewDidLoad). Double check your UIScrollView's contentSize.