Radar 37650722 describes the following bug (as of iOS 11.2.6):
- Create an app with a simple UITableView with enough rows to require scrolling. (I use UITableView as an easy example, but this happens with any UIScrollView.)
- Run that app on an iPad.
- Put the iPad in landscape orientation.
- Scroll to the bottom of the table.
- Press the home button to leave the app.
- Open the app again.
Expected Results: I would expect the table view to remain scrolled to the bottom.
Actual Results: The table view is no longer scrolled to the bottom.
This project demonstrates the issue. It also includes the code I used to address this in Unread.
To incorporate the fix in your app, do the following:
-
Copy GHSScrollPositionFix.swift into your project.
-
Add a GHSScrollPositionFix to your view controller.
var scrollPositionFix: GHSScrollPositionFix?
- In your viewDidLoad method, create the scroll position fix:
self.scrollPositionFix = GHSScrollPositionFix(scrollView: self.tableView)
- Call the viewWillTransition method of scrollPositionFix from the viewWillTransition method of the view controller:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
self.scrollPositionFix?.viewWillTransition(to: size, with: coordinator)
}
The code can be used from Swift or from Objective-C.
Pull requests welcome.