iOS: Autolayout causing UIScrollView to not scroll

后端 未结 3 615
抹茶落季
抹茶落季 2021-01-04 08:18

I have set up a UIScrollView with which I want to display 12 images (only 8 fit on screen) laid out horizontally. In the following image you can see the problem

相关标签:
3条回答
  • 2021-01-04 08:52

    Insert: [scrollView setContentSize:CGSizeMake(x,y)]; in the following method:

    -(void)viewWillAppear:(BOOL)animated
    
    0 讨论(0)
  • 2021-01-04 08:55

    Two Solutions:

    1. Create different constraints that can be satisfied simultaneously (you will have to edit). I think the problem is your bottom space and top space constraints are mutually exclusive. please remove one and try again. IF this is difficult for you, try adding another UIView to contain the UIScrollView to help manage your constraints, it might seem odd at first, but sometimes adding another view to contain your view actually makes it simpler at each level.

    2. Turn off Autolayout, and change the autoresize masks of your UIImageView to be what you wish.

    0 讨论(0)
  • 2021-01-04 09:12

    Try to set your scrollView's Content size int "viewDidLayoutSubviews" method with keeping the autolayouts set.

    -(void)viewDidLayoutSubviews
    {
      [self.itemList setContentSize:CGSizeMake(required_width, required_height)];
    }
    
    0 讨论(0)
提交回复
热议问题