2012-04-25 11 views
0

我正在做一個iPhone應用程序中的iOS 5我的應用程序是非常緩慢的,而這樣做捏手勢識別

在說我擴大和重裝的UITableView同時承認捏合手勢。

它在模擬器中很好用。但是在設備中它工作得很慢。例如,在UIGestureRecognizerStateEnded之後的設備中,只有所有的行都會被展開,但在模擬器中,當UIGestureRecognizerStateChanged本身時,行正在展開和重新加載。

有關內存問題的任何建議?

我的代碼是在這裏

if (pinchRecognizer.state == UIGestureRecognizerStateBegan) { 

    self.initialPinchHeight = rowHeight; 

    [self updateForPinchScale:pinchRecognizer.scale]; 
} 
else { 
    if (pinchRecognizer.state == UIGestureRecognizerStateChanged) { 
     [self updateForPinchScale:pinchRecognizer.scale]; 

    } 
    else if ((pinchRecognizer.state == UIGestureRecognizerStateCancelled) || (pinchRecognizer.state == UIGestureRecognizerStateEnded)) { 
    } 
} 

-(void)updateForPinchScale:(CGFloat)scale{ 

CGFloat newHeight = round(MAX(self.initialPinchHeight * scale, DEFAULT_ROW_HEIGHT)); 

rowHeight = round(MIN(30.0, newHeight)); 
/* 
Switch off animations during the row height resize, otherwise there is a lag before the user's action is seen. 
*/ 
BOOL animationsEnabled = [UIView areAnimationsEnabled]; 
[UIView setAnimationsEnabled:NO]; 
[self.tableView beginUpdates]; 
NSArray *visibleRows = [self.tableView indexPathsForVisibleRows]; 
[self.tableView reloadRowsAtIndexPaths:visibleRows withRowAnimation:UITableViewRowAnimationNone]; 
[self.tableView endUpdates]; 
[UIView setAnimationsEnabled:animationsEnabled]; 
} 

回答

0

試圖找出優化是什麼,你應該測量哪裏出了問題之前。您可以使用時間配置文件和核心動畫工具進行此操作。使用Xcode的產品菜單並選擇配置文件。確保您連接到設備時的配置文件,如您所注意的那樣,它具有與模擬器不同的性能特徵。

時間檔案工具將幫助您識別在CPU上完成的工作。 Core Animation工具將幫助您識別Core Animation在CPU和GPU上所做的工作。請注意0​​調試選項複選框。它們有點神祕,但會幫助您直觀地識別出讓Core Animation做了很多工作的部分UI。

適用於iOS的不同儀器的文檔是here

我也推薦覆蓋Core Animation的WWDC video

+0

嗨,謝謝你的回覆,在我的代碼中,我犯了一個錯誤。錯誤是我重新加載了beginupdates和endupdates之間的行。解決這個問題之後,我的應用在我的iPhone上正常工作。 – Jirune 2012-04-26 06:02:42