iOS 判断指定cell 是否离开可视区

2017-02-09  本文已影响675人  不知蜕变的挣扎

在许多情况下,需要判断指定cell是否在可视区域内,但是没有系统的方法来直接判断。
只能通过获得cell的fram,通过计算来判断。


// 指定cell的row
NSString *index = [[NSUserDefaults standardUserDefaults] objectForKey:VoiceIndex];

// 指定cell的indexpath
NSUInteger newIndex[] = {0, [index integerValue]};
NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];

if (newPath != nil) {
     // 获得 指定cell的fram
    CGRect cellrect =  [_tableView rectForRowAtIndexPath:newPath];
    // tableview滑动距离 - cell的fram 的绝对值 与 tableview的高度对比
    if (fabs(_tableView.contentOffset.y - cellrect.origin.y) > _tableView.size.height ) {
        // 不在可视区范围内
           .......
     } else {
        // 在可视区范围内
           .......
    }
}

上一篇 下一篇

猜你喜欢

热点阅读