开发者

iphone - UIScrollview - scrollRectToVisible with slow animation

开发者 https://www.devze.com 2023-01-25 23:10 出处:网络
I\'m using UIScrollView and using scrollRectToVisible:animated This is working fine for me. But I want to scroll to a location slowly so that user can notice the effect.

I'm using UIScrollView and using scrollRectToVisible:animated This is working fine for me. But I want to scroll to a location slowly so that user can notice the effect. Is it possible.

I'm trying the following code, but didn't succeed.

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:2.0];  
[scrlView scrollRectToVisible:<<some cgrect>> animated:YES];            
[UIView commitAnimations];          开发者_StackOverflow


The solution is actually pretty easy. If you use [scrollView scrollRectToVisible:frame animated:YES] the scrollview will start it's own animation, so in order to animate with your duration you have to use [scrollView scrollRectToVisible:frame animated:NO] within your animation.

In other words: This will work.

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

精彩评论

暂无评论...
验证码 换一张
取 消