Search code examples
objective-cios11xcode9

UIScrollView setContentOffset:animated not working in iOS11


I added a method to make the scroll view to scroll to top of it. This is working as expected in iOS10. But when I upgraded to iOS11 with Xcode 9, it is not working. Is there anything that am missing respective to iOS11.
Below code was working:

[self setContentOffset:CGPointZero animated:YES];

Updating question after comment from OP (UPDATE)

I find the reason why setContentOffset:animated is not working, I use UITableView and I make some custom cell in my tableview, tableview has a property "estimatedRowHeight" , we should make this property equal "0", I guess when iOS11 calculate it's content size it will use "estimatedRowHeight", if we don't set this property , it will use system default.

This is very useful and should be more visible


Solution

  • try this

    dispatch_async(dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:.25 animations:^{
            [self setContentOffset:CGPointZero animated:YES];
        }];
    });