首页 > 解决方案 > ImageView frame is not changing while scrolling in Xcode 11.0 (11A420a)

问题描述

I have a UIView on top of another UIView. In that top view I have a UIImageView and on top of that there is a scrollVIew. When scrolling it used to stretch the imageView frame calculating the scroll offset. Now updating to Xcode 11.0 (11A420a) this feature is not working even though nothing has changed. Any suggestion why ? Here is my imageView constraints:

enter image description here

and my scrollViewDidScroll function:

 func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let y = 135 - (self.scrollView.contentOffset.y + 135)
    let h = max(120, 160 + y)
    let rect = CGRect(x: 0, y: 0, width: view.bounds.width, height: h)
    NHBannerImageView.frame = rect
}

As you can see there is a rect variable which value changes depending on scroll but after that image frame is not changing.

I have downloaded the Xcode 10.3 and its working straight away, with the same configuration.

标签: swiftxcode11

解决方案


Update your view layout might be solve this problem. Add -

self.view.layoutIfNeeded()

in scrollViewDidScroll


推荐阅读