Issue with UIScrollView not scrolling smoothly with Auto Layout on iOS 15
I'm testing a new approach and I'm converting an old project and I'm working on an iOS 15 app where I need a UIScrollView to contain a dynamically generated content view that adjusts with Auto Layout. Despite setting up the constraints correctly, the scrolling feels laggy and unresponsive. I've confirmed that the content size of the UIScrollView is being updated based on the content view's size, but it seems like scrolling is stuttering. Here's a snippet of my setup: ```swift override func viewDidLoad() { super.viewDidLoad() setupScrollView() } private func setupScrollView() { let scrollView = UIScrollView() scrollView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(scrollView) NSLayoutConstraint.activate([ scrollView.topAnchor.constraint(equalTo: view.topAnchor), scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor), scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) let contentView = UIView() contentView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(contentView) NSLayoutConstraint.activate([ contentView.topAnchor.constraint(equalTo: scrollView.topAnchor), contentView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), contentView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor), contentView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor), contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor) ]) // Adding dynamic content to contentView... } ``` I've tried several approaches, such as wrapping my content in a UIStackView and adjusting the layout updates explicitly on the main thread, but nothing seems to improve the performance. Additionally, I noticed that if the content view has more than a certain number of subviews, the scrolling becomes even more sluggish. I did some profiling using Instruments and saw that the main thread seems to be getting blocked at times. Does anyone have insights on how to ensure smoother scrolling in UIScrollView when dealing with dynamic content and Auto Layout on iOS 15? Are there any best practices or common pitfalls I might be missing? The stack includes Swift and several other technologies. What am I doing wrong? I'm on Linux using the latest version of Swift.