Toque en ScrollView llamadas `scrollViewWillBeginDecelerating` cuando la vista de desplazamiento se establece pagingEnabled en YES

Cuando scrollViewWillBeginDecelerating en ScrollView, llama a los methods scrollViewWillBeginDecelerating y scrollViewDidEndDecelerating incluso después de que el scrollView's se establece pagingEnabled en YES

Tengo scrollView con subViews y trato de configurar contentOffset acuerdo con subViews . Pero no funciona.

Aquí está mi código:

 self.myScrollView.frame = CGRectMake(0, 0, pageWidth, pageHeight); self.myScrollView.contentSize = CGSizeMake(pageWidth * self.contentViewControllers.count, pageHeight); for (NSInteger i = 0; i < self.contentViewControllers.count; i++) { UILabel *label = [UILabel new]; label.textColor = [UIColor whiteColor]; label.textAlignment = NSTextAlignmentCenter; label.text = [NSString stringWithFormat:@"Page %ld",i]; label.backgroundColor = [UIColor randomColor]; label.frame = CGRectMake(i * pageWidth, 0, pageWidth, pageHeight); [self.myScrollView addSubview:label]; } self.myScrollView.contentInset = UIEdgeInsetsMake(120, 0, 0, 0); self.myScrollView.contentOffset = CGPointMake(0, - 120); self.myScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(120, 0, 0, 0); - (UIScrollView *)myScrollView{ if (!_myScrollView) { _myScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero]; _myScrollView.backgroundColor = [UIColor blackColor]; _myScrollView.pagingEnabled = YES; _myScrollView.directionalLockEnabled = YES; _myScrollView.delegate = self; //_myScrollView.delaysContentTouches = NO; //_myScrollView.scrollsToTop = NO; } return _myScrollView; } 

Cuando subView en cualquier subView dentro de scrollView , llama a los methods de delegado:

scrollViewWillBeginDecelerating >> scrollViewDidScroll >> scrollViewDidEndDecelerating

Y el contenido contentOffset cambia a {0,0}

Actualiza tu código de esta forma:

Configure contentSize after for loop.

 self.myScrollView.frame = CGRectMake(0, 0, pageWidth, pageHeight); for (NSInteger i = 0; i < self.contentViewControllers.count; i++) { UILabel *label = [UILabel new]; label.textColor = [UIColor whiteColor]; label.textAlignment = NSTextAlignmentCenter; label.text = [NSString stringWithFormat:@"Page %ld",i]; label.backgroundColor = [UIColor randomColor]; label.frame = CGRectMake(i * pageWidth, 0, pageWidth, pageHeight); [self.myScrollView addSubview:label]; } self.myScrollView.contentInset = UIEdgeInsetsMake(120, 0, 0, 0); self.myScrollView.contentOffset = CGPointMake(0, - 120); self.myScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(120, 0, 0, 0); self.myScrollView.contentSize = CGSizeMake(pageWidth * self.contentViewControllers.count, pageHeight); - (UIScrollView *)myScrollView{ if (!_myScrollView) { _myScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero]; _myScrollView.backgroundColor = [UIColor blackColor]; _myScrollView.pagingEnabled = YES; _myScrollView.directionalLockEnabled = YES; _myScrollView.delegate = self; //_myScrollView.delaysContentTouches = NO; //_myScrollView.scrollsToTop = NO; } return _myScrollView; }