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