5

我希望 UIScrollView 始终滚动回特定点。我通过写作实现了它:

   - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset 
{
    (*targetContentOffset).x = 0.0f;
}

它工作得很好,有一个例外。当我滚动足够远并到达视图的末尾(然后开始弹跳)并向上拉我的手指时,视图只是平滑地滚动并稍微向后减速,停止然后跳转(没有动画)我设置它的位置。只要我不滚动到滚动视图的末尾,它就不会发生。

这是我如何初始化 UIScrollView

  scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 284, frame.size.height)];
  scrollView.backgroundColor = [UIColor clearColor];
  scrollView.delegate = self;

  [scrollView setContentSize:CGSizeMake(285,frame.size.height)];
  [self addSubview:scrollView];

  UIEdgeInsets inset = scrollView.contentInset;
  inset.left = 60;
  inset.right = 60;
  [scrollView setContentInset:inset];
4

2 回答 2

0

当您到达滚动视图内容的边界时,弹跳效果是默认行为,您可以通过将反弹属性设置为NO来关闭它:

yourscrollView.bounces = NO;

我相信这只是您在这里面临的问题。

于 2012-07-11T13:53:08.680 回答
0

6 年后,反弹动画和 targetContentOffsetForProposedContentOffset 方法之间仍然存在这种冲突......

于 2018-10-11T13:21:01.167 回答