模拟UIScrollView Deceleration [英] Simulate UIScrollView Deceleration
问题描述
我有一个 UIPanGestureRecognize
,我用它来更改视图的框架。当手势状态为时,有没有办法模拟
?这是我目前的代码: UIScrollView
或 UITableView
的减速度UIGestureRecognizerStateEnded
I have an UIPanGestureRecognize
which I use to change the frame of a view. Is there a way to simulate the deceleration of the UIScrollView
or UITableView
when the gesture's state is UIGestureRecognizerStateEnded
? Here is my current code:
if (panGesture.state == UIGestureRecognizerStateEnded)
{
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.view.frame = CGRectMake(182, 0, self.view.frame.size.width, self.view.frame.size.height);
}
completion:^(BOOL finished) {
if (finished) {
//Do something
}
}];
}
但这不是一个平滑的滚动。我希望减速直到它停止到我设定的位置。谢谢
but this is not a smooth scroll. I would like something that decelerates until it stops to the point I've set. Thanks
推荐答案
WWDC 2012上的会议223,使用滚动视图增强用户体验,介绍了使用scrollview行为的方法和感觉为不同视图的位置设置动画(没有滚动视图实际上对用户可见)。
Session 223 at WWDC 2012, "Enhancing User Experience With Scroll Views", covered a method to use a scrollview's behavior and "feel" to animate the position of a different view (without the scrollview ever actually being visible to the user).
会话中显示的方法的好处是你的减速总是与UIScrollView相匹配,现在和永远。
The benefit of the method shown in the session is that your deceleration would always match UIScrollView's, now and forever.
https://developer.apple.com/videos/wwdc/2012/?id=223
这篇关于模拟UIScrollView Deceleration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!