0

In this time I'm write pod, custom pageViewController. And in this work I have one problem.

I have scrollView. On this scrollView I have 3\5\7 ViewControllers. They are small and on Scroll view We can see half of first VC, second VC and third VC.

pagingEnabled on ScrollView is On. And if we scroll VC move and scrollView change focused zone.

If we move scroll fast or touch for one size of screen and move to other size then we move from first screen to third VC.

http://prntscr.com/bhfqfn

http://prntscr.com/bhfqr8

http://prntscr.com/bhfrdq

pragma mark - UIScrollViewDelegate

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
if (0 > velocity.x) {
    if ([self.dataSource respondsToSelector:@selector(pageViewController:viewControllerBeforeViewController:)]) {
        if (self.scrollView.contentOffset.x <= self.internalViewControllers.firstObject.view.frame.size.width + self.view.frame.size.width) {
            UIViewController *newViewController = [self.dataSource pageViewController:self viewControllerBeforeViewController:self.internalViewControllers.firstObject];
            if (newViewController) {
                [self popRightViewCintroller];
                [self pushLeftViewController:newViewController];
                [self moveViewControllers];
                targetContentOffset->x = scrollView.contentOffset.x;
                [scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x + self.scrollView.frame.size.width, 0) animated:NO];
            }
        }
    }
}
if (0 < velocity.x) {
    if ([self.dataSource respondsToSelector:@selector(pageViewController:viewControllerAfterViewController:)]) {
        if (self.scrollView.contentOffset.x >= self.internalViewControllers.lastObject.view.frame.origin.x - self.view.frame.size.width * 2) {
            UIViewController *newViewController = [self.dataSource pageViewController:self viewControllerAfterViewController:self.internalViewControllers.lastObject];
            if (newViewController) {
                [self popLeftViewCintroller];
                [self pushRightViewController:newViewController];
                [self moveViewControllers];
                targetContentOffset->x = scrollView.contentOffset.x;
                [scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x - self.scrollView.frame.size.width, 0) animated:NO];
            }
        }
    }
} }

- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
[self moveViewControllers]; }

pragma mark - Helpers

- (void)moveViewControllers {
int numberOfFocusetView = floor(self.scrollView.contentOffset.x / self.scrollView.frame.size.width);
CGFloat contentOffsetView;
if (numberOfFocusetView > 0) {
    contentOffsetView = self.scrollView.contentOffset.x - (numberOfFocusetView * self.scrollView.frame.size.width);
} if (numberOfFocusetView == 0) {
    contentOffsetView = self.scrollView.contentOffset.x;
}
if (numberOfFocusetView >= 0) {
    UIViewController* centralVC = self.internalViewControllers[numberOfFocusetView];
    contentOffsetView = contentOffsetView / (self.scrollView.frame.size.width / (self.scrollView.frame.size.width - self.childVCSize.width - self.sizeBetweenVC));
    CGFloat form = 0;
    if (self.animationSpeed == 0) {
        self.animationSpeed = 1;
    }
    switch (self.animation) {
        case defaultAnimation:
            form = 0;
            break;
        case easeIn:
            form = sinf(contentOffsetView / (self.scrollView.frame.size.width - self.childVCSize.width - self.sizeBetweenVC) * M_PI) * self.animationSpeed;
            break;
        case easeOut:
            form = -sinf(contentOffsetView / (self.scrollView.frame.size.width - self.childVCSize.width - self.sizeBetweenVC) * M_PI) * self.animationSpeed;
            break;
        case easeBorder:
            form = sinf(contentOffsetView / (self.scrollView.frame.size.width - self.childVCSize.width - self.sizeBetweenVC) * M_PI*2) * self.animationSpeed;
            break;
        case easeCenter:
            form = -sinf(contentOffsetView / (self.scrollView.frame.size.width - self.childVCSize.width - self.sizeBetweenVC) * M_PI*2) * self.animationSpeed;
            break;
        default:
            break;
    }
    CGFloat originX = (self.spaceHorizontal + (self.scrollView.frame.size.width * numberOfFocusetView) + contentOffsetView);
    centralVC.view.frame = CGRectMake(originX + form, self.spaceVertical, self.childVCSize.width, self.childVCSize.height);
    [self changeViewControllersOriginXBy:centralVC withNumber:numberOfFocusetView];
} }

- (void) changeViewControllersOriginXBy:(__kindof UIViewController *) centralVC withNumber:(NSInteger) numberOfFocusetView {
for (int i = 0; i < self.internalViewControllers.count; i++) {
    if (i != numberOfFocusetView) {
        CGFloat originXForView = centralVC.view.frame.origin.x + (self.childVCSize.width + self.sizeBetweenVC) * (i - numberOfFocusetView);
        self.internalViewControllers[i].view.frame = CGRectMake(originXForView, self.spaceVertical, self.childVCSize.width, self.childVCSize.height);
    }
} }

Someone can help me?

  • http://stackoverflow.com/questions/35980582/uicollectionview-with-customflowlayout-how-to-restricts-scroll-to-only-one-page – Wain Jun 16 '16 at 16:19
  • You can never see a view controller; you can only see its views. – Caleb Jun 16 '16 at 18:21

0 Answers0