简体   繁体   English

UIScrollView不会反弹

[英]UIScrollView doesn't bounce

I have a UIScrollView contained within a custom UIView with a content size larger than the ScrollView's frame. 我有一个UIScrollView 包含在自定义UIView中 ,其内容大小大于ScrollView的框架。

I am able to drag scroll as I expect, but the thing doesn't give me the rubber banding effect that you get with the UITableView or UIWebView. 我可以像我期望的那样拖动滚动,但是这件事并没有给我你用UITableView或UIWebView获得的橡皮筋效果。 It just stops when you get to one of the extremes. 当你到达一个极端时它就会停止。

I have set bounce = YES , is there something else I'm supposed to do? 我设置了bounce = YES ,还有什么我应该做的吗?

I read the docs, and they say I have to implement the delegate. 我阅读了文档,他们说我必须实现代理。 I did that. 我做到了

They also say I should change the zoom levels, but I don't want the user to actually be able to zoom so I haven't set these. 他们还说我应该更改缩放级别,但我不希望用户实际上能够缩放,所以我没有设置这些。

For anyone that finds this thread later, if you are subclassing UIView and re-setting the UIScrollView 's frame on every layoutSubviews , that is the problem - it cancels the bounce: 对于以后找到此线程的任何人,如果你是UIView的子类并在每个layoutSubviews上重新设置UIScrollView的框架,那就是问题 - 它取消了反弹:

http://openradar.appspot.com/8045239 http://openradar.appspot.com/8045239

You should do something similar to this: 你应该做类似的事情:

- (void)layoutSubviews;
{
    [super layoutSubviews];

    CGRect frame = [self calculateScrollViewFrame];
    if (!CGRectEqualToRect(frame, self.scrollView.frame)) 
        self.scrollView.frame = frame;
}

I had the same problem, on a UIScrollView that wasn't all filled up (but I still wanted it to bounce). 我有同样的问题,在UIScrollView上并没有全部填满(但我还是希望它反弹)。 Just setted: 刚刚设定:

scroll.alwaysBounceVertical/Horizontal = YES;

And it worked as expected 它按预期工作

It turns out that keeping the UIScrollView within my custom UIView was causing the trouble. 事实证明,将UIScrollView保留在我的自定义UIView中会导致麻烦。

Once I switched my custom UIView to instead inherit from UIScrollView, then the bouncing started working. 一旦我将自定义UIView切换为从UIScrollView继承,然后弹跳开始工作。

That is interesting... Is there a lot going on while the user scrolls the scroll view? 这很有趣......当用户滚动滚动视图时,有很多事情发生吗? Maybe that could cause the problem. 也许这可能会导致问题。 The iPhone can multitask, but not too much. iPhone可以多任务,但不能太多。 Can I see your entire code having to do with the scroll view? 我可以看到您的整个代码与滚动视图有关吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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