inc*_*inc 5 objective-c uiscrollview ios
我有两个水平的UIScrollViews与PagingEnabled.
在纵向模式下一切正常,但在横向上我在滚动视图之间遇到冲突.例如,如果当前可见视图是ScrollView2.View2,我滚动到ScrollView1.View3,ScrollView2滚动以及ScrollView1.它以某种方式接收滚动ScrollView1的事件.结果我得到ScrollView2.contentOffset等于0.0(但它应该等于View2的X,例如384.0).
是否可以确定滚动哪个滚动?我尝试使用UIScrollViewDelegate方法修复,但是没有帮助我,如果我放置WebViews而不是Views,事情会变得更糟.
正如我之前提到的,我尝试在"didScroll"和其他委托方法中检查scrollview的实例,但是在这种方法中同步所有内容并不容易.我试图覆盖hitTest方法,也没有帮助我.
我还没有找到将事件传递到正确滚动视图的方法。但这是让它发挥作用的一些因素:
首先,您需要在所有嵌套的 UIScrollView 中禁用 Paging Enabled (因为嵌套的 UIScrollView 将与父 UIScrollView 一起滚动)。
实现嵌套ScrollView的分页:
/*
* User stopped dragging the innerScroll, the view is not decelerating
* and it is still not at its place. Lets help the view to get into right place.
*/
-(void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if ([scrollView isEqual:innerScroll] && !decelerate) {
if(scrollView.contentOffset.x <= view1.frame.size.width/2){
[innerScroll scrollRectToVisible:view1.frame animated:YES];
} else {
[innerScroll scrollRectToVisible:view2.frame animated:YES];
}
}
}
/*
* User stopped dragging the innerScroll and the View is decelerating.
* Lets skip an efforts of the View to get into right place and put it ourselves.
*/
- (void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
if ([scrollView isEqual:innerScroll]) {
if(scrollView.contentOffset.x <= view1.frame.size.width/2){
[innerScroll scrollRectToVisible:view1.frame animated:YES];
} else {
[innerScroll scrollRectToVisible:view2.frame animated:YES];
}
}
}
Run Code Online (Sandbox Code Playgroud)
当您内部 UIScrollView 尚未到达最后一个视图时,禁用和启用父 UIScrollView。
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if([scrollView isEqual:innerScroll]){
if(CGRectIntersectsRect(scrollView.bounds, view1.frame)){
if(CGRectIntersectsRect(filterScroll.bounds, view11.frame)){
} else if(CGRectIntersectsRect(filterScroll.bounds, view22.frame)){
}
mainScroll.scrollEnabled = NO;
} else if (CGRectIntersectsRect(scrollView.bounds, view2.frame)){
mainScroll.scrollEnabled = YES;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1348 次 |
| 最近记录: |