UIScrollView with scaled UIImageView using autolayout

后端 未结 3 2373
广开言路
广开言路 2021-02-20 04:51

\"UIScrollView

Consider a UIScrollView with a single subview. The subview is an

3条回答
  •  走了就别回头了
    2021-02-20 05:23

    In my case it was a full width UIImageView the had a defined height constraint that causing the problem.

    I set another constraint on the UIImageView for the width that matched the width of the UIScrollView as it is in interface builder then added an outlet to the UIViewController:

    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageViewWidthConstraint;
    

    then on viewDidLayoutSubviews I updated the constraint:

    - (void) viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
    
        self.imageViewWidthConstraint.constant = CGRectGetWidth(self.scrollView.frame);
    }
    

    This seemed to do the trick.

提交回复
热议问题