One way to solve this problem is to configure contentOffset to view the scroll of webviews after the rotation. Due to changes in line breaks in texts, the overall page size may change during rotation.
So, to solve this problem, you need to save the old size of the content of the webviews in the "willRotateToInterfaceOrientation" method, then calculate the relative change in the "didRotateFromInterfaceOrientation" method and adjust the contentOffset content to scroll. (This "almost" solves the problem - I say almost because because of the changes in line breaks you can go one or two lines out of the desired position.)
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { oldSize = self.webView.scrollView.contentSize; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { CGSize newSize = self.webView.scrollView.contentSize; float xFactor = newSize.width / oldSize.width; float yFactor = newSize.height / oldSize.height; CGPoint newOffset = webView.scrollView.contentOffset; newOffset.x *= xFactor; newOffset.y *= yFactor; webView.scrollView.contentOffset = newOffset; }
Tobi source share