代码之家  ›  专栏  ›  技术社区  ›  Andy Waite

测量平滑滚动性能

  •  0
  • Andy Waite  · 技术社区  · 14 年前

    在iPhone应用程序中,是否有任何方法可以测量滚动性能,例如每秒更新次数?我正在尝试各种技术来提高滚动性能,但有时很难判断它们是否真的有效果。

    1 回复  |  直到 14 年前
        1
  •  2
  •   Ed Marty    14 年前

    如果有滚动委托,则可以实现该方法 scrollViewDidScroll: . 明确地:

    //header:
    @interface MyClass : NSObject <UIScrollViewDelegate> {
        CFAbsoluteTime last;
        int updateCount;
        CFTimeInterval timeTotal;
    }
    @end
    
    //implementation:
    @implementation MyClass
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        CFAbsoluteTime time = CFAbsoluteTimeGetCurrent();
        if (last > 0) {
            timeTotal += time - last;
            ++updateCount;
            if (timeTotal > 1) {
                NSLog(@"Updates Per Second: %.2f", updateCount / timeTotal);
                updateCount = 0;
                timeTotal = 0;
            }
        }
        last = time;
    }
    
    @end
    

    像那样。它未经测试,因此日志记录可能不正确。但要使用它,只需将您的代表分配给 scrollview.delegate 财产。