I have a problem with my UIScrollView and I hope some of you can help me in some way.
I explain you ...
At the center of my ViewController I have a ScrollView showing the contents of 3 external UIViewController. Through classic for loops I am able to properly display the contents and so far I have not found any problems ...
The problem arises when I perform scrolling between the view controller (horizontally) or, the content of each view controller moves, it does not remain as it was initially set. Now I can not figure out if the problem depends ScrollView or by content, but I think it is a problem of content viewcontroller because I used the autolayout to set constraints ...
At this point I think it's a problem that arises in the ScrollView when I make scrolling to show the next viewcontroller.
Below I insert the screen shoots to show my situation .. as you can see the contents are moved to the right and do not remain in the X position zero.
Can you help me figure out where I'm wrong? what code and 'wrong ..
ScreenShoot
code used
-(void)initializeViewControllerTour {
/* Inserisce in una NSMutableArray i ViewController inizializzati da utilizzare*/
_a_TourVC = [[UPATour alloc] init];
_a_TourVC = [self.storyboard instantiateViewControllerWithIdentifier:@"A_Tour_App"];
_b_TourVC = [[UPBTour alloc] init];
_b_TourVC = [self.storyboard instantiateViewControllerWithIdentifier:@"B_Tour_App"];
_c_TourVC = [[UPCTour alloc] init];
_c_TourVC = [self.storyboard instantiateViewControllerWithIdentifier:@"C_Tour_App"];
_containerArrayVC = [[NSMutableArray alloc] init];
[_containerArrayVC addObject:_a_TourVC];
[_containerArrayVC addObject:_b_TourVC];
[_containerArrayVC addObject:_c_TourVC];
NSInteger index = 0;
/* Imposta i valori per la ScrollView */
CGSize scrollViewSize = CGSizeMake([_containerArrayVC count] * _scrollView.frame.size.width, _scrollView.frame.size.height);
_scrollView.contentSize = scrollViewSize;
_scrollView.scrollEnabled = YES;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.pagingEnabled = YES;
_scrollView.delegate = self;
/* Imposta il PageControl */
_pageControl.userInteractionEnabled = NO;
_pageControl.numberOfPages = [_containerArrayVC count];
_pageControl.currentPage = index;
/* Crea il ciclo For per i ViewController basandosi sulla MutableArray */
for (_currentViewController in _containerArrayVC) {
[self addChildViewController:_currentViewController];
CGFloat originx = (index) * _scrollView.frame.size.width;
_currentViewController.view.frame = CGRectMake(originx, 0, _scrollView.frame.size.width, _scrollView.frame.size.height);
[_scrollView addSubview:_currentViewController.view];
[_currentViewController didMoveToParentViewController:self];
index ++;
}
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat pageW = _scrollView.frame.size.width;
CGFloat segmentPage = _scrollView.contentOffset.x / pageW;
NSInteger page = lround(segmentPage);
_pageControl.currentPage = page;
}