UIScrollView 和 targetContentOffset 无法正常工作

msm*_*lko 5 cocoa animation scroll uiscrollview ios

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

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

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

这是我如何初始化 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];
Run Code Online (Sandbox Code Playgroud)

tig*_*ero 0

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

yourscrollView.bounces = NO;
Run Code Online (Sandbox Code Playgroud)

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