5

I am adding a dummy ScrollView to my app to detect a user click on the status bar, to performa an event in my program.. I am creating it in the ViewDidLoad:

//Dummy Scroll is for the tap on status bar to work 

UIScrollView *dummyScrollView = [[UIScrollView alloc] init]; 
dummyScrollView.delegate = self; 
[[self view ] addSubview:dummyScrollView]; 
[[self view] sendSubviewToBack:dummyScrollView];  

I then implement :

 - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView 
 { 

NSLog(@"scrollViewShouldScrollToTop");
 .
 .
 }

Under all previous versions of IOS this has worked beautifully and flawlessly, yet under iOS 6 the scrollViewShouldScrollToTop never gets called. Is this a bug?? The API says this should still be available as part of the delegate in iOS6, yet under iOS6 on both device and simulator it never executes... Anyone have any idea what is going on?

Still no other TableView or ScrollView, but there is a MAPVIEW?? But the MapView doesn't have a shouldScrollToTop that I can find to set to NO.. so I am still beyond confused why this stopped working under iOS 6...

Speckpgh
  • 3,332
  • 1
  • 28
  • 46

2 Answers2

5

Is there any chance that the UIScrollView you're creating isn't somehow the only UIScrollView in your view hierarchy? It looks like in iOS6, if you have more than a single UIScrollView in your view hierarchy, only one should have scrollsToTop = YES. This is the one that'll have its scrollViewShouldScrollToTop method called.

My problem was similar in that I had a very basic UITableView that would no longer autoscroll to the top when the status bar was tapped. I finally remembered that one of the cells in my tableView uses a UIWebView, and that the cell's webView.scrollView was (correctly, now in iOS6) hijacking the call to scrollViewShouldScrollToTop that, before iOS6, was being made on my tableView.

After setting the tableViewCell's "scrollsToTop = NO", the status bar autoscroll once again worked as it did before. Here's more-or-less how the code looks:

myCustomCellWithAWebView.webView.scrollView.scrollsToTop = NO;

Hope this helps!

John Jacecko
  • 1,870
  • 1
  • 16
  • 12
  • 1
    FYI, this isn't a new behaviour in iOS6 - it's been around a long time. See http://stackoverflow.com/questions/4167806/automatic-scroll-to-top-doesnt-work-in-uitableview/5557900#5557900 – Martin Lockett Oct 04 '12 at 11:49
  • There are no other scroll views in my app, other than the hidden one used to trigger the click on the status bar to fire off the event. – Speckpgh Oct 11 '12 at 02:45
  • What happens if you don't send it to the back? Does it work if you leave it on top? If so, leave it on top and set the alpha to 0 or position it off screen, perhaps. – Zev Eisenberg Oct 22 '12 at 16:49
  • Worth noting this is documented, albeit in a hidden-away corner. Check out `UIScrollVIew.h`: `// On iPhone, we execute this gesture only if there's one on-screen scroll view with scrollsToTop == YES. If more than one is found, none will be scrolled.` – Tim Arnold May 07 '15 at 17:31
0

On iOS 6, only tap the part above scrollview of status bar can fire scrollsToTop event.

And, that scrollView can't be hidden or 0 alpha.

But it can be covered. or clear background color.

So on iOS 6, you need

dummyScrollView.frame = self.view.bounds;
dummyScrollView.backgroundColor = [UIColor clearColor];  
sycx
  • 891
  • 6
  • 8