uiview动画是在设置动画的过程中添加加速度



我正在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];
                 }
 ];

第一种方法是正常工作。第二种方式的问题是在动画制作过程中添加加速度。不要得到

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

您发布的两个代码示例不等价;您的设置代码应该发生在动画块之前,而实际导致动画的"结束状态"代码应该在"动画"块中。与你的第一个样本相当的区块是:

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

这有帮助吗?

最新更新