2012-05-04 35 views
1

如何計算在圖像視圖中加載圖像所用的時間。我在點擊按鈕上使用此代碼如何計算在圖像視圖中加載圖像所用的時間

-(IBAction)loadImage:(id)sender 
{ 
    //Using block to create image view through NSOperationQueue 
    NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
    [queue addOperationWithBlock: ^{ 

    //Create image view and adding it to the view 
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 375)]; 
    imageView.image = [UIImage imageNamed:@"Yellow_Red_Parrot.jpg"]; 
    [self.view addSubview:imageView]; 

    }]; 
} 

我想計算從點擊圖像加載到圖像視圖所花費的時間。任何人都可以幫助我。

在此先感謝

+0

首先,你應該只在主線程上做UIKit的東西。其次,你可能不會從中得到任何準確的信息。圖像數據將被加載到核心動畫事務中,這不會與分配圖像視圖的圖像同時發生,甚至不會將其添加爲子視圖。 –

回答

2

開始操作之前,添加:

NSDate *startDate=[NSDate date]; 

操作結束後,添加:

NSDate *endDate=[NSDate date]; 
double ellapsedSeconds=[endDate timeIntervalSinceDate:startDate];