代码之家  ›  专栏  ›  技术社区  ›  Satyam

iphone-UIScrollview-scrollRectToVisible和慢速动画

  •  19
  • Satyam  · 技术社区  · 14 年前

    我正在使用UIScrollView和scrollRectToVisible:animated 这对我很有用。 但我想慢慢滚动到一个位置,这样用户就可以注意到效果。 有可能吗。

    我正在尝试下面的代码,但没有成功。

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:2.0];  
    [scrlView scrollRectToVisible:<<some cgrect>> animated:YES];            
    [UIView commitAnimations];          
    
    1 回复  |  直到 14 年前
        1
  •  56
  •   voidStern    13 年前

    解决方法其实很简单。如果你使用 [scrollView scrollRectToVisible:frame animated:YES] scrollview将启动它自己的动画,因此为了在持续时间内动画化,必须使用 [scrollView scrollRectToVisible:frame animated:NO] 在你的动画里。

    换言之:这是可行的。

    [UIView animateWithDuration:3 
                          delay:0 
                        options:UIViewAnimationOptionCurveEaseInOut 
                     animations:^{ [scrollView scrollRectToVisible:frame animated:NO]; } 
                     completion:NULL];