怎么判断某个cell是否显示在屏幕上

 时间:2026-02-14 09:08:19

1、首先,在成为某个视图的子视图时,先移除之前的kVO,然后对视图层级中所有class为UIScrollView的contentSize添加KVO。

怎么判断某个cell是否显示在屏幕上

2、然后,输入程序- (void)didMoveToSuperview {

    [self unKVO];

    UIView *aView = self.superview;

    while (aView) {

      if ([aView isKindOfClass:[UIScrollView class]]) {

        [self observer:aView forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:(void *)__LINE__];

      } aView = aView.superview;   } }

怎么判断某个cell是否显示在屏幕上

3、然后,需要设置TableViewseparatorStyle属性UITableViewCellSeparatorStyleNone即除划。代码:tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

怎么判断某个cell是否显示在屏幕上

4、当然,如果记录KVO了哪些视图的,方便及时移除:

- (BOOL)isDisplayedInScreen

{ if (self == nil) { return FALSE; }CGRect screenRect = [UIScreen mainScreen].bounds;

怎么判断某个cell是否显示在屏幕上

5、然后,打印监测到的值变化:

static NSMutableArray *receiverArr;  static SunTableViewCell *cell;  - (void)observer:(NSObject *)receiver forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context {    if (cell && cell != self) {      return;    }    cell = self;    [receiver addObserver:self forKeyPath:keyPath options:options context:context];    if (!receiverArr) {      receiverArr = [NSMutableArray array];    }    [receiverArr addObject:receiver];  }  - (void)dealloc {    [self unKVO];

怎么判断某个cell是否显示在屏幕上

6、最后,获取 该view与window 交叉的 Rect

    CGRect intersectionRect = CGRectIntersection(rect, screenRect);

    if (CGRectIsEmpty(intersectionRect) || CGRectIsNull(intersectionRect)) {

 return FALSE; } return TRUE;}

怎么判断某个cell是否显示在屏幕上

  • 如何查手机生产日期
  • 手机生产日期怎么查
  • 怎么查看手机生产日期
  • 怎么看手机生产日期
  • 手机出厂日期查询方法
  • 热门搜索
    手刹怎么用 矛盾的结晶体怎么获得 手机充不上电怎么回事 八卦图怎么画 怎么把两张图片合成一张 小孩疝气怎么治疗 怎么安装系统 怎么分真假玉 journey怎么读 word底纹怎么设置