我使用的UIScrollView加载我的两个视图让说A和B。 它究竟看起来像下面的图片。 我设置PagingEnabled为YES和DirectionLockEnabled为YES。
当我拖累从A视图到B它去对角。 请从下面的代码,
- (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;
}
}
我检查这些以下链接,但我我以前不得到解决然而, http://bogdanconstantinescu.com/blog/proper-direction-lock-for-uiscrollview.html UIScrollView中只在一个方向同时滚动 的http:// chandanshetty01.blogspot.ae/2012/07/restricting-diagonal-scrolling-in.html
所有帮助表示赞赏!