Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11: Scroll to top when "adjustedContentInset" changes with larger title bars?

I noticed that this code doesn't quite work as expected on iOS 11, because the "adjustedContentInset" property value changes as the "navigationBar" shrinks during a scroll:

CGFloat contentInsetTop=[scrollView contentInset].top;

if (@available(iOS 11.0, *))
{
    contentInsetTop=[scrollView adjustedContentInset].top;

}
////

[scrollView setContentOffset:CGPointMake(0, -contentInsetTop) animated:YES];

... For example, this might start out as 140, then reduce to 88 beyond a minimal scroll offset. This means if you call this, it doesn't actually scroll all the way to the top.

Aside from preserving the original offset in memory from when the UIScrollView loads, is there a way to recover this value later to ensure that it does indeed scroll to top consistently, no matter the "adjustedContentInset"?

like image 904
Ben Guild Avatar asked Sep 13 '17 09:09

Ben Guild


1 Answers

Currently, there is indeed no way to do this with iOS 11, I have heard. The only way to do so is to capture the initial value and store it for the life of the navigation/view controller.

I will update my answer accordingly if I hear otherwise, but it will be broken in the base iOS 11 release forever unfortunately.

like image 113
Ben Guild Avatar answered Oct 21 '22 16:10

Ben Guild