I have several view controllers with one or multiple scrollviews. Although I have explicitly set the scrollsToTop
flags in view controllers with more than one scrol
I have used code like the following to debug this scenario, before:
- (void)findMisbehavingScrollViews
{
UIView *view = [[UIApplication sharedApplication] keyWindow];
[self findMisbehavingScrollViewsIn:view];
}
- (void)findMisbehavingScrollViewsIn:(UIView *)view
{
if ([view isKindOfClass:[UIScrollView class]])
{
NSLog(@"Found UIScrollView: %@", view);
if ([(UIScrollView *)view scrollsToTop])
{
NSLog(@"scrollsToTop = YES!");
}
}
for (UIView *subview in [view subviews])
{
[self findMisbehavingScrollViewsIn:subview];
}
}
Depending on how many UIScrollViews you find, you can modify that code to help debug your particular situation.
Some ideas:
Ideally, you should only find a single UIScrollView in the window hierarchy that has scrollsToTop set to YES.
I changed the accepted answers into swift for convenience:
func findMisbehavingScrollViews() {
var aview = UIApplication.sharedApplication().keyWindow
findMisbehavingScrollViewsIn(aview!)
}
func findMisbehavingScrollViewsIn(aview: UIView) {
if aview.isKindOfClass(UIScrollView) {
if (aview as! UIScrollView).scrollsToTop {
print("found uiscrollview \(aview)")
}
}
for bview in aview.subviews {
findMisbehavingScrollViewsIn(bview)
}
}