2

私は以下のようなアニメーションを使用してiOSのマーキーテキストに取り組んでいます:

最初の方法:

-(void)startScrolling {
      CGRect rect ;
      rect                   =   self.titleView.frame;
      rect.origin.x          =   -self.titleView.frame.size.width;
      self.titleView.frame   =   rect;
      [UIView beginAnimations:@"" context:nil];
      [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
      [UIView setAnimationDuration:13];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDidStopSelector:@selector(startScrolling)];

      // Update end position
      CGRect rect ;
      rect                   =   self.titleView.frame;
      rect.origin.x          =   [[UIScreen mainScreen] bounds].size.width;
      self.titleView.frame   =   rect;
      [UIView commitAnimations];

}

2番目の方法:

      [UIView animateWithDuration:13
                            delay:0
                          options:UIViewAnimationOptionCurveLinear
                       animations:^{
                           CGRect rect ;
                           rect                   =   self.titleView.frame;
                           rect.origin.x          =   -self.titleView.frame.size.width;
                          self.titleView.frame    =   rect;

                 }
                      completion:^(BOOL finished) {
                          CGRect rect ;
                          rect                   =   self.titleView.frame;
                          rect.origin.x          =   [[UIScreen mainScreen] bounds].size.width;
                         self.titleView.frame    =   rect;
                         [self startScrolling];
                 }
 ];

最初の方法は正しく機能することです。2番目の方法の問題は、アニメーション中に加速が追加されることです。取得しないでください

ブロック使用中に加速が追加される理由。インターネットで検索していますが、まだ行き詰まっています。この問題について何かアイデアはありますか?

4

1 に答える 1

2

投稿した 2 つのコード サンプルは同等ではありません。セットアップ コードはアニメーション ブロックの前に発生する必要があり、実際にアニメーションを発生させる「終了状態」コードは「アニメーション」ブロックにある必要があります。最初のサンプルに相当するブロックは次のようになります。

       CGRect rect ;
       rect                   =   self.titleView.frame;
       rect.origin.x          =   -self.titleView.frame.size.width;
      self.titleView.frame    =   rect;

      [UIView animateWithDuration:13
                            delay:0
                          options:UIViewAnimationOptionCurveLinear
                       animations:^{
                          CGRect rect ;
                          rect                   =   self.titleView.frame;
                          rect.origin.x          =   [[UIScreen mainScreen] bounds].size.width;
                         self.titleView.frame    =   rect;
                 }
                      completion:^(BOOL finished) {
                         [self startScrolling];
                 }
 ];

それは役に立ちますか?

于 2013-02-18T17:00:04.563 に答える