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];

}

第二种方式:

      [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];
                 }
 ];

第一种方法是正常工作。第二种方式的问题是在动画过程中添加了加速度。不明白

为什么在使用块时添加加速。在互联网上搜索,但我仍然卡住了。对这个问题有什么想法吗?

4

1 回答 1

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 回答