I am using UIScrollview to load my two views let say A and B. It exactly looks like the below picture. I set PagingEnabled as YES and DirectionLockEnabled as YES.
When I drag the view from A to B it goes diagonally. Please find the code below,
- (void)setupScrollView:(UIScrollView*)scrMain {
for (int i = 0; i < 2; i++) {
if (i == 0) {
// View A
[ViewA setFrame:CGRectMake((i)*scrollview.frame.size.width + 20, 0, scrollview.frame.size.width - 40, ViewA.frame.size.height)];
[scrollview addSubview:ViewA];
} else if (i == 1) {
// View B
[ViewB setFrame:CGRectMake((i)*ViewB.frame.size.width + 30, 0, scrollview.frame.size.width - 40, ViewB.frame.size.height)];
[scrollview addSubview:ViewB];
}
}
[scrollview setContentSize:CGSizeMake((scrollview.frame.size.width-15)*2, ViewB.frame.size.height)];
}
- (void) scrollViewWillBeginDragging: (UIScrollView *) scrollView
{
self.oldContentOffset = scroller.contentOffset;
}
- (void) scrollViewDidScroll: (UIScrollView *) scrollView
{
float XOffset = fabs(self.oldContentOffset.x - scrollView.contentOffset.x );
float YOffset = fabs(self.oldContentOffset.y - scrollView.contentOffset.y );
if (scrollView.contentOffset.x != self.oldContentOffset.x && (XOffset >= YOffset) )
{
scrollView.pagingEnabled = YES;
scrollDirection = ScrollDirectionHorizontal;
}
else
{
scrollView.pagingEnabled = NO;
scrollDirection = ScrollDirectionVertical;
}
}
I check with these following links but I did't get a solution yet, http://bogdanconstantinescu.com/blog/proper-direction-lock-for-uiscrollview.html UIScrollView scrolling in only one direction at a time http://chandanshetty01.blogspot.ae/2012/07/restricting-diagonal-scrolling-in.html
All Helps are appreciated!!