UIScrollView has a property called scrollsToTop which sets y of content offset of scrollview to zero on tapping the statusbar. But there might be situation when this functionality does not work.
According to apple documentation "The scroll-to-top gesture is a tap on the status bar. When a user makes this gesture, the system asks the scroll view closest to the status bar to scroll to the top. If that scroll view has scrollsToTop set to NO, its delegate returns NO from scrollViewShouldScrollToTop:, or the content is already at the top, nothing happens.
After the scroll view scrolls to the top of the content view, it sends the delegate a scrollViewDidScrollToTop: message.
The default value of scrollsToTop is YES.
Special Considerations according to apple documentation:
On iPhone, the scroll-to-top gesture has no effect if there is more than one scroll view on-screen that has scrollsToTop set to YES."
So according to the documentation if on iPhone a view has more than one scrollview with scrollsToTop set to YES, none of the scrollviews will be scrolled to top on tapping status bar. Now we will have to set scrollsToTop property of all other scroll views except to that of the required scrollview to NO.
One more thing that should be taken into consideration is that UIScrollView has subclasses which may be UITableView or UITextView. Also UIWebView contains a scrollview within it. So we should also check for these components.
Here is a small workaround code from stackoverflow that might be helpful :
- (void) disableScrollsToTopPropertyOnAllSubviewsOf:(UIView *)view {
for (UIView *subview in view.subviews) {
if ([subview isKindOfClass:[UIScrollView class]]) {
((UIScrollView *)subview).scrollsToTop = NO;
}
[self disableScrollsToTopPropertyOnAllSubviewsOf:subview];
}
}
References:
- apple documentation
- stackoverflow
0 Comment(s)