简体   繁体   中英

UIScrollView and targetContentOffset doesn't work properly

I want UIScrollView to always scroll back to the specific point. I've achieved it by writing:

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

it works pretty fine with one exception. When I scroll far enough and reach the end of the view (bouncing starts then) and pull my finger up, the view just scrolls smoothly with deceleration a little back, stops and then jumps (without animation) where I set it. It doesn't happen as long as I don't scroll to the end of the scroll view.

Here's how I init 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];

The bouncing effect is a default behavior when you are reaching the boundaries of the content of scrollview you can turn it off by setting the bounces property to NO :

yourscrollView.bounces = NO;

I believe this is only the issue you are facing here.

6年后仍然存在跳出动画与targetContentOffsetForProposedContentOffset方法之间的冲突......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM