0

I want to resize the superview with respect to its subview.

The scenario is that I have a scroll view inside it there is a view with different subviews. Within the subviews, there is a ContainerView with embedded view controller. Which have a table view. I want to increase the size of the table view as the cell increases and in the same the increase the height of view- container - view and scroll view, Because the table wont scroll.

i was able to increase the size of the table view following the link enter link description here

but i am stuck how can i increase the size of the embedded view. enter image description here

To elaborate more i am attaching images from a project i am practicing on.

enter image description here

  • Purple is the color of the main view controller.
  • Green is scroll view.
  • Grey is view inside scroll view.
  • Blue is the color of embedded View controller.
  • Red is the color of table view. but cant be seen on simulator as it has resized according to the number of cells.

    -(CGSize)sizeForChildContentContainer:(id<UIContentContainer>)container
               withParentContainerSize:(CGSize)parentSize
    {
    
         //    int height = _containerView.frame.size.height;
         NSLog(@"height of container");
         return _tableView.frame.size;
    }
    
    -(void)adjustHeightOfTableview
    
    {
    
         CGFloat height =  self.tableView.contentSize.height;
         CGFloat maxHeight = self.tableView.superview.frame.size.height -  self.tableView.frame.origin.y;
    
    
         // if the height of the content is greater than the maxHeight of
         // total space on the screen, limit the height to the size of the
         // superview.
    
        if (height > maxHeight)
            height = maxHeight;
    
        // now set the height constraint accordingly
    
        [UIView animateWithDuration:0.25 animations:^{
           self.tableViewHeightConstraint.constant = height;
           [self.view setNeedsUpdateConstraints];
    
        }];
    
        [_tableView setNeedsLayout];
        [_tableView layoutIfNeeded];
    }
    

In the same way or some thing like that i need to resize the view. I have searched for some thing similar but i did not got a clear answer, any kind of help will be appreciated.

Community
  • 1
  • 1
Sam Shaikh
  • 1,596
  • 6
  • 29
  • 53

0 Answers0