2010-06-04 42 views
0

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

回答

2

如果您有滚动委托,您可以实施方法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属性即可。