我希望 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];