2

UILabelテキスト付きの「メモ」(サブクラス化)を表示しているiPadアプリがあります。次のノートに移動するには、次のノートを右からスライドさせながら、画面から左にスライドさせてください。どちらかのアニメーションを動作させることはできますが、両方を同時に動作させることはできません。

これが私のコントローラーのコードです:

- (void)slideOutLeft {
    // create the new note
    flSlidingNote *newNote = [[flSlidingNote alloc] init];
    newNote.text = @"blah blah";
    CGRect newFrame = CGRectMake(1000, 70, 637, 297); // off the right
    newNote.frame = newFrame;
    [self.view addSubview:newNote];

    // slide off the current one
    CGRect currentFrameEnd = noteLabel.frame; // noteLabel is the existing note
    currentFrameEnd.origin.x = 0 - noteLabel.frame.size.width; // off the left

    [UIView animateWithDuration:1.0 animations:^{
        noteLabel.frame = currentFrameEnd;
    } completion:nil];
}

noteLabelまったくアニメートしません。addSubview:newNote私がその部分をコメントアウトすると、それはします。私はまだ比較的新しいので、おそらく単純なものです。

問題は、アニメーション化されているかどうかに関係なく発生newNoteします(コードスニペットではアニメーション化されていません)。

4

3 に答える 3

1

Gabriele Petronella のコメントに加えて、サンプルの GitHub プロジェクトがリンクされた、KeyFrames と AnimationGroup に関する優れたリソースを次に示します。

http://blog.corywiles.com/using-caanimationgroup-for-view-animations

これは、アニメーションをよりよく理解するのに本当に役立ちました。

于 2013-02-07T13:50:37.447 に答える
1

次のように、ビューの両方のアニメーションと新しいビューの addSubview 呼び出しを 1 つのアニメーション ブロックに配置します。

  // layout the new label like the old, but 300px offscreen right 
  UILabel * newNote = [[UILabel alloc] initWithFrame:CGRectOffset(self.noteLabelView.frame, 300, 0)];
  newNote.text = @"NEW NOTE";

 [UIView animateWithDuration:2.0f
                       delay:0
                     options:UIViewAnimationCurveEaseInOut
                  animations:^{
                     // animate the old label left 300px to offscreen left
                     self.noteLabelView.center = CGPointMake(self.noteLabelView.center.x-300, self.noteLabelView.center.y);
                     // add the new label to the view hierarchy
                     [self.view addSubview:newNote];
                     // animate the new label left 300px into the old one's spot
                    newNote.center = CGPointMake(newNote.center.x-300, newNote.center.y);
                  }
                  completion:^(BOOL finished) {
                    // remove the old label from the view hierarchy
                    [self.noteLabelView removeFromSuperview];
                    // set the property to point to the new label
                    self.noteLabelView = newNote;
               }];

上記のこのスニペットでは、古いラベルはプロパティを介してアドレス指定できると想定していますself.noteLabelView

https://github.com/algal/SlidingNotesもご覧ください。ただし、それが長く続くとは約束できないため、SO はそのようなリンクに適した形式ではないのでしょうか?)

于 2012-12-11T00:45:59.050 に答える
-1

よくわかりませんが、サブビューをループしてアニメーションを実行する他のコードを見たことがあります。次のことを試してください。

for(UIView *view in self.subviews)
{
    // perform animations 
}
于 2012-12-10T22:50:44.813 に答える