如何在一次移动中将事件从外部滚动传递到内部滚动

时间:2013-12-16 06:42:17

标签: ios iphone objective-c uiscrollview scroll

我有两个scrollView,其中一个在其他内部, -OuterScroll ---- InnerScroll

当外部ScrollView达到大于300的contentOffSet值时,需要外部scrollView自动停止并在单个滚动中启动内部。

到目前为止..

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
    if (scrollView ==scrollSuperView)
    {

        if (scrollView.contentOffset.y>300) {
            [scrollContentView setScrollEnabled:YES];
        }else if (scrollView.contentOffset.y<10){
            [scrollContentView setScrollEnabled:NO];
        }

     }
 }

顺便说一句,scrollSuperView是outerScroll,scrollContentView是内部的。 任何帮助表示赞赏。

1.scrollSuperView(外部)  frame = CGRect(0,0,320,468)  contentSize = CGSizeMake(320,600)

2.scrollContentView(内部)  frame = CGRect(0,300,320,468)  contentSize = CGSizeMake(320,600)

所以我上面提到了两个外部和内部的scrollViews 一旦外部scrollView达到&gt; 300的内容偏移量,那么如果用户通过将手指放在内部ScrollView上滚动,则scrollEvent会被传递到内部ScrollView。

希望现在更清楚。

2 个答案:

答案 0 :(得分:1)

scrollView delaysContentTouches NO设置为scrollView会将触摸事件从外部scrollView传递到内部-(void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == scrollSuperView) { //outer scrollView if (scrollView.contentOffset.y >= 300) { //NSLog(@"Outer scrollView ContentOffset has reached 300"); [scrollSuperView setDelaysContentTouches:NO]; [scrollContentView setScrollEnabled:YES]; } } else if (scrollView == scrollContentView) { //inner scrollView if (scrollView.contentOffset.y == 0) { //NSLog(@"Inner scrollView ContentOffset has reached 0"); [scrollSuperView setDelaysContentTouches:YES]; [scrollContentView setScrollEnabled:NO]; } } } ......“单动

scrollSuperView

假设:

  1. scrollContentView Outer
    • frame = CGRect(0,0,320,300)
    • contentSize = CGSizeMake(320,600)
    • delaysContentTouches = YES
    • scrollEnabled = YES
  2. {{1}}( Inner
    • frame = CGRect(0,400,320,200)
    • contentSize = CGSizeMake(320,400)
    • delaysContentTouches = YES
    • scrollEnabled = NO

答案 1 :(得分:0)

-(void)viewDidLoad{
 //write your code here
 innerScrollView.scrollEnabled =NO;
 outerScrollView.scrollEnabled =YES;
 //above two lines makes touch(scroll) events given to outer and not inner.
}

你修改过的方法,

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
    if (scrollView ==scrollSuperView)
    {

        if (scrollView.contentOffset.y>300) {
            outerScrollView.scrollEnabled =NO;
            innerScrollView.scrollEnabled =YES;
            [outerScrollView setContentOffset:CGPointMake(0, 200)];
     }
 }
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    [self.view endEditing:YES];
    if (scrollView ==scrollSuperView && decelerate==NO)
    {

        if (scrollView.contentOffset.y>300) {
            outerScrollView.scrollEnabled =NO;
            innerScrollView.scrollEnabled =YES;
            [outerScrollView setContentOffset:CGPointMake(0, 200) animated:YES];
     }
 }
}