According to Apple's documentation (and many other places) UIScrollViewDelegate: scrollViewWillEndDragging: withVelocity: targetContentOffset is not called if UIScrollView.pagingEnabled is set to YES. However, on iOS6 this seems to be true, however on iOS7 it ALWAYS gets called for me, no matter what pagingEnabled is installed.
Here is a simple test view controller:
@interface ViewController () <UIScrollViewDelegate> @property (weak, nonatomic) IBOutlet UIWebView *webView; @end @implementation ViewController - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { NSLog(@"%d", scrollView.pagingEnabled); } - (void)viewDidLoad { [super viewDidLoad]; [self loadHTML]; [self configureWebView]; } - (void)loadHTML { NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"htmlContent" ofType:@"html"]; NSString* htmlString = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; [_webView loadHTMLString:htmlString baseURL:nil]; } - (void)configureWebView { [_webView.scrollView setDelegate:self]; _webView.scrollView.pagingEnabled = YES; } @end
In iOS7, if pagingEnabled == YES, the NSLog in scrollViewWillEndDragging prints 1, if it is set to NO, it prints 0.
In iOS6, when pagingEnabled == YES, console output:
Stop offset can not be modified for paging scroll views
When it is NOT, the output is 0.
Does anyone else understand this? Does anyone know if this will be the case in iOS7? The documentation has not changed, so I suppose not, but I thought I would ask you all to submit an error report with Apple and add checks for pagingEnabled in all my delegated calls.
ios objective-c uiscrollview uiscrollviewdelegate
Jordan bondo
source share