【问题标题】:Objective-C UICollectionView Scroll Up/DownObjective-C UICollectionView 向上/向下滚动
【发布时间】:2013-09-28 16:14:39
【问题描述】:

有谁知道,UICollectionView 在向上/向下滚动时使用什么方法。 我需要在向下滚动时更改 UICollectionView 的标题。我正在做自己的日历视图。

我有以下方法为部分创建标题视图

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{

    ASCalendarHeaderView *calHeader = [self.calCollectView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"CalendarHeader" forIndexPath:indexPath];

    calHeader.MonthYearLabel.text = [calendar getCurrentMonthYear:calendar.today];
    [calHeader setNeedsDisplay];
    calHeader.MonthYearLabel.textAlignment = NSTextAlignmentRight;

    if (indexPath.section){

        [calendar getNextMonth:calendar.today];
        NSLog(@"Some Text");

    }

    return calHeader;
}

但是当我向上滚动时它会增加月份。有没有分别表示向上滚动和向下滚动的方法?

谢谢

【问题讨论】:

    标签: ios objective-c scroll uicollectionview


    【解决方案1】:

    检查此方法以检测滚动:

    - (void)scrollViewDidScroll:(UIScrollView *)sender
    

    每次滚动都会调用它,如果你想知道滚动是向上还是向下,注册上一个滚动的偏移量,如果更多,则向上,反之亦然:

    @property (nonatomic, assign) NSInteger lastOffset;
    
    - (void)scrollViewDidScroll:(UIScrollView *)sender 
    {
       //Compare sender.contentOffset.y with lastOffset
    
    lastOffset = sender.contentOffset
    
    }
    

    【讨论】:

    • 对不起,我想了,但是我怎样才能在这个方法中为 CollectionView 做 Header 更改?
    • 不是每次都创建一个新的标头,只需有一个带有标头的类变量并在您的方法中返回它。因为它是一个类变量,所以您可以随时访问它并更改任何您想要的内容
    • 你能举一些例子,方向吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 2015-07-17
    • 2014-10-06
    • 1970-01-01
    相关资源
    最近更新 更多