0

私はiOS 5でiPhoneアプリをやっています。

その中で、ピンチ ジェスチャを認識しながら、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];
}
4

1 に答える 1

0

何を最適化するかを理解する前に、問題がどこにあるかを測定する必要があります。これは、TimeProfileおよびCoreAnimationインスツルメントを使用して行うことができます。Xcodeの[製品]メニューを使用して、[プロファイル]を選択します。お気づきのように、シミュレータとは異なるパフォーマンス特性を持つデバイスに接続しているときに、プロファイルを作成してください。

Time Profileインスツルメントは、CPUで実行された作業を識別するのに役立ちます。Core Animationインストゥルメントは、CPUとGPUの両方でCoreAnimationによって実行されている作業を識別するのに役立ちます。CoreAnimation機器の[デバッグオプション]チェックボックスに注意してください。これらは少しわかりにくいですが、CoreAnimationに多くの作業を行わせているUIの部分を視覚的に識別するのに役立ちます。

iOSで利用可能なさまざまな機器に関するドキュメントはこちらです。

CoreAnimationをカバーするWWDCビデオもお勧めします。

于 2012-04-25T06:06:18.353 に答える