Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView-分离scrollViewDidScroll和scrollToItemAtIndexPath_Ios_Objective C_Cocoa Touch_Uicollectionview - Fatal编程技术网

Ios UICollectionView-分离scrollViewDidScroll和scrollToItemAtIndexPath

Ios UICollectionView-分离scrollViewDidScroll和scrollToItemAtIndexPath,ios,objective-c,cocoa-touch,uicollectionview,Ios,Objective C,Cocoa Touch,Uicollectionview,我的屏幕有一个日历视图,下面是一个UICollectionView,其中包含按日期排序的事件列表 当用户更改日历中的月份时,我使用UICollectionView scrollToItemAtIndexPath将collection视图滚动到该月份的事件 当用户在UICollectionView中滚动时,我使用scrollViewDidScroll和UICollectionView indexPathsForVisibleItems来检测滚动并更改日历以匹配可见事件的月份 现在,问题是更改日历月

我的屏幕有一个日历视图,下面是一个
UICollectionView
,其中包含按日期排序的事件列表

当用户更改日历中的月份时,我使用
UICollectionView scrollToItemAtIndexPath
将collection视图滚动到该月份的事件

当用户在
UICollectionView
中滚动时,我使用
scrollViewDidScroll
UICollectionView indexPathsForVisibleItems
来检测滚动并更改日历以匹配可见事件的月份

现在,问题是更改日历月会调用
scrollToItemAtIndexPath
,这会触发
scrollViewDidScroll
,这会更改日历月,这。。。你明白了


有没有办法把这两个电话分开?我想我只想在用户滚动触发的情况下调用
scrollViewDidScroll
,但我对任何其他达到我目标的解决方案都很满意。

这就是我最终要做的-感觉很不舒服,但它可以工作。如果有人有更干净的方法,我很高兴听到

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // Don't change calendar month if currently scrolling
    if (scrolling)
        return;

    // change calendar month
}

- (void)scrollEventsToCurrentMonth {
    // find index path
    // scroll to index path

     scrolling = TRUE;
     [self performSelector:@selector(stoppedScrolling) withObject:NULL afterDelay:0.5];
}

- (void)stoppedScrolling {
    scrolling = FALSE;
}

UICollectionView
继承自
UIScrollView
。因此,您可以访问
跟踪
属性,以确定“用户是否触摸了内容以启动滚动。”

这里看似迟钝的措辞是指用户可能已经开始触摸,但尚未开始滚动。但是,如果视图在用户未开始触摸的情况下滚动,则可以安全地假定为编程滚动